I have 2 server sockets accepting connections on ports X and Y. Both registered on selector.
One connection on first server socket has to be mapped to another connection on other server socket.
Messages on connection on first server socket must be passed over to connection on second server socket and vice versa.
How do we handle the mapping part.
You are saying that the client is making two connections with the server, correct?
Have the client pass over some form of ID, like a username, which you can use to pair the two connections. If you don't want them to use a username then instead when they connect pass an ID to them (an integer for example) which they pass back to you when they make the second connection.
You can store the two connection in two serperate hashmaps with the id as the key, or in a holding class that stores the two connection and keep that in a single hashmap or list, or you can do it some other way.
You mean to say that the other client must send its first message with some unique identfier in the packet?
Let me know if I am wrong in understanding.
Assuming that my understanding in correct, i would require to parse each message in isReadable() to see if the unique identifier is present in it or not.
Is there any other way which can be thought of?