Hello,

I have two applications; a server and a client which use simple TCP Sockets to connect to each other and send the data.

The only problem I have is that I am struggling to associate usernames with the accepted sockets on the server. The server is able to accept and hold multiple socket connections in order for multi-user chat and I have set up a simple string list ready for the usernames but since I am unable to find any socket IDs or such-like, I can't find a way to associate a name with a socket.

I have looked in to socket connected listener or w/e, but even then, I am unable to send username data with the connect method.

Any help is appreciated,
Thanks.

Recommended Answers

All 3 Replies

can't find a way to associate a name with a socket

I don't think you can. Just send the username as the first data.

Ok. I was going to do that as a last resort since multiple people might connect at once and mix up the names. Thanks anyway.

Ok. I was going to do that as a last resort since multiple people might connect at once and mix up the names. Thanks anyway.

You can't. Data comes down each socket from a specific client (unless you're using Broadcast). So if you keep that socket in a particular method that expects a certain "Initialisation" data, then there's no chance of mixing names up.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.