Click here to Skip to main content
15,031,495 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more: (untagged)
What's the best solution for doing non blocking sockets in Java? The Socket class in and of itself doesn't support this. I'm aware of NIO but have heard rumors that's not very good or perhaps tricky to use?
I found Apache's MINA ([^]) which looks promising, but wondered what people here have used.


1 solution

the easiest is to create the ServerSocket listening on it's own thread. The listening thread is blocked, but you can still call the close() method.
This will cause a SocketException to be thrown on the listening thread to allow for graceful exit.

See Class:ServerSocket[^] for details.


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900