Is there a way to implement a socket server that services clients serially.
Generally the practice is to dispatch connected clients to a new thread that services requests and response however amounting to one thread per client on the server side.
I don’t want to do this because I later want to port this app to Java ME that may have a limit on the number of concurrent threads running at a point of time.
I was wondering how to solve this problem?
Sure, just don’t fire off a background thread to handle the client.
EDIT
It seems like what you really want is for a large number of clients to be able to connect, but not create a load of threads. Since NIO doesn’t appear to be supported how about using two threads:
Socketto the second thread which just adds it to a list of connected sockets (this needs to be synchronized)Calling
socket.setSoTimeout()with a reasonably small value should prevent the second thread waiting for too long on one connection.