I am creating a chat application in Java. I am having no trouble having a server accept multiple client socket connections and maintaining multiple threads. I already managed to get them to send and receive messages.
However, I cannot figure out how to create multiple socket connections to the same specific client. On both the server and the client I already have a thread for sending and receiving chat messages. I would like to have another connection on top of that to do background stuff, such as sending files, while continuing to relay chat messages.
For example, Client1 and Client2 are messaging each other through the server, which keeps a database of accounts and chat messages. I would like to be able to send a file from Client1 to Client2 and vice versa.
Connection1: Client1 <--message--> Server <--message--> Client2
Connection2: Client1 --file--> Server --file--> Client2
or
Connection2: Client1 --file--> Client2
I was thinking about how each clients have IP addresses and I could use those to create the new connection. However, since I'm running this on localhost, all of the IP addresses are identical so I cannot do it this way.