Search code examples
javanio

With Java NIO, how do you distinguish between clients?


This may be a terribly naive question but I was just wondering if the client would have to send a "client id" of some sort along with every packet to be able to identify who it is from. I couldn't seem to notice any other form of client identification.

Thanks


Solution

  • In NIO you still have a connection object, the Channel. Each channels talk exactly to one client in the same way you would do it with plain Socket streams. So you have to identify your client only at the start of the connection.