How to make an accepted socket non-blocking in java?

And If you want to accept multiple clients you want to use a loop The basic structure of a multi-client server is: while (true) // accept connections // spawn thread to deal with that connection } If the issue is blocking on the accept() call, well that's what accept() does: it blocks waiting for a connection. If that's an issue I suggest you have a separate thread to accept connections See Writing the Server Side of a Socket.

And If you want to accept multiple clients you want to use a loop. The basic structure of a multi-client server is: while (true) // accept connections // spawn thread to deal with that connection } If the issue is blocking on the accept() call, well that's what accept() does: it blocks waiting for a connection. If that's an issue I suggest you have a separate thread to accept connections.

See Writing the Server Side of a Socket.

I would expect your code to block on the accept call, never getting to the configureBlocking call. I typically spin off a separate thread for each socket connection, and let it block until a connection is actually made/accepted This allows the main thread to continue unblocked while it is waiting for client connections.

If the typical blocking socket doesn't give you the availability you need (a connection every 100ms does seem tight). You should look at a non-blocking socket. Here is a tutorial.

You can also look at Apache MINA to make this easier.

If you're looking for non-blocking sokets, my suggestion is to use Selectors and ServerSocketChannels with the NIO package. java.sun.com/j2se/1.4.2/docs/guide/nio.

One approach is to use an I/O loop (event loop) in a single threaded environment. Take a look at Deft web server for inspiration. (Especially the start() method in IOLoop).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions