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

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.