I'm making a multi-threaded UDP client/server application in Java and have run into a little snag. I have a 'solution' in mind, but I'm 90% sure that it is a patchy fix to this issue.
Let's call host 1's threads Client 1 and Server 1 (C1 & S1), and host 2's threads Client 2 and Server 2 (C2 & S2). All of these extend Thread and override run(), while the clients also include some other methods ( e.g. chat() to initiate a chat between hosts). I then start each respective client/server pair via a third class that calls start().
To get data flowing, I create a socket for the C1/S2 and C2/S1 pairs and send/receive UDP datagrams through it. However, my clients need to respond to the other client's chat message, and hence S1 must also talk to C1, and S2 to C2.
What would be the best way of setting this communication up? I thought that I could for example create another socket on localhost for each of these machines (based in the client class/thread), to have a single host's client/server threads talk to each other, but this seems more like a workaround rather than a solution. Is there a better way?