Hi there fellow Javaers,
Background story, skip if you want:
[i]After migrating most code from using php as a “server” I moved over to servlets to reuse some checks I already have in java instead of rewriting them in php. Now I took another step and moved over to sockets (mostly so that the server can initiate communication with the clients instead of the clients needing to poll constantly).
As I like to write everything from scratch (I do this mostly to challenge myself anyway and I want to be in control of my code) I already spent something like 15 hours to get sockets up and running to a point where I can send either clear or compressed code to the clients, I have some error handling for socket interruptions and no code is blocking the CPU. My initial tests are extremely satisfying and the performance of the server is great, even with several connected clients.[/i]
Sometimes I want the client to send information to the server and await a response and sometimes I want the server to send information to the applet and await a reply.
What is the best way around this? What if the client sends something to the server and goes into waiting mode, but before the server recieved the request the server initiates a send itself, therefore making the client think that what the client recieves from the server is the response to to the client’s request, while it actually is the request from the server?
I guess I could create two socket connections with the server and bind the server to two ports (one for client initiated and one for server), but there must be a smarter way to solve this, or?
Thanks in advance,
Mike