Creating a Non-Blocking Server Socket
This example shows how to create a non-blocking server socket. A
non-blocking server socket requires a server socket channel.
See also Using a Selector to Manage Non-Blocking Server Sockets.
// Create a non-blocking server socket and check for connections
try {
// Create a non-blocking server socket channel on port 80
ServerSocketChannel ssChannel = ServerSocketChannel.open();
ssChannel.configureBlocking(false);
int port = 80;
ssChannel.socket().bind(new InetSocketAddress(port));
// See Accepting a Connection on a ServerSocketChannel
// for an example of accepting a connection request
} catch (IOException e) {
}
Post a comment