- How do I send the request from the server? I can't use http requests since the client isn't running an http server, do I have to use sockets? or is there some other Apache library to make it easier?
Yes this is a good use for sockets. Apache does have some useful tools to help with this but implementing a basic server client socket connection isn't to difficult by itself
- How do I receive the message asynchronously in the client?
This part gets into how you implement your threads and send/receive data from the server. You should break apart your work and build out into 2 parts
Create the client and server connections. Build out all the functionality you need to send and receive data from a server, build in some calls that let the client know they need to work on
other_stuff
.Create the Threads that are required for
other_stuff
,stuff
and the socket connection. This would at least consist of 2 threads, 1 for the socket connection and 1 forstuff
andother_stuff
. Depending on whatstuff
andother_stuff
do you may want to break those into 2 different threads that useThread.notify
andThread.wait
to interrupt each other when the socket connection receives the right messages.
Both of these 2 topics have many tutorials and code samples online so I wont make any here. But as I said break apart your project into 2 parts and it will be an easier build out. I think a good starting point might be creating your client and simulating your server by using the System.in
for "prentend" responses from the server