Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I uniquely identify a client connection in Winsock

Status
Not open for further replies.

TrueCode

MIS
Sep 30, 2003
71
LC
I am testing a setup with multiple clients hitting a server which creates dynamic answering sockets. I need to know from the server side which connection belongs to which client later to send that client messages. Is there a way for me to have the client to send a specific requestid that I can accept or reject?



------------------------------------->

"I have sought your assistance on this matter because I have exhausted all the help that I can find. You are free to direct me to other source of help"
 
TrueCode,

You can send over the user name, machine name or even use the socket handle as the identifier.

Andy
 
Dave

If I clear understand, when the client makes a successful connect to the server, have it to immediately send a sort of an ID data which I can use at the Servers Dataarrival method of that connected socket to rename it with the data sent by the client. Thereafter, the server can reference that socket by its new name when it wishes to send data to specific socket/connection/client.



------------------------------------->

"I have sought your assistance on this matter because I have exhausted all the help that I can find. You are free to direct me to other source of help"
 
TrueCode,

I know your question is directed at Dave, but I'll throw in my 2 cents while I'm here.

If you're just looking for a behind the scenes unique identifier then the Socket Handle will do (Winsock.SocketHandle property). You get the socket handle immediately when the connection is established and you use this in the .Accept() method. Using this handle can always tell where the message came from and where any response needs to go.

If you need something more readable then sending an ID message is the way to go as Dave suggests. I used this in a situation where the user could click on connections at the server (using a listview) and see information about the connection. Having something readable (like the computer name) was desireable so the user could tell where the connection was coming from.

Andy
 
okay guys, I can see how my solution can marry both of your suggestions. Thanks. But Dave's is what I needed. I want to be able to send data to the client with something like

thisform.senddata(ClientName,MsgType,PassCode)

Where the custom senddata method in the form will find the correct connected socket for the that client and use its .senddata() to send data the desired client.


Thanks alot, I am trying it out presently.


------------------------------------->

"I have sought your assistance on this matter because I have exhausted all the help that I can find. You are free to direct me to other source of help"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top