The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.nio  [27 examples] > Sockets  [8 examples]

e177. 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 e179 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 e178 Accepting a Connection on a ServerSocketChannel
        // for an example of accepting a connection request
    } catch (IOException e) {
    }

 Related Examples
e173. Creating a Non-Blocking Socket
e174. Reading from a SocketChannel
e175. Writing to a SocketChannel
e176. Using a Selector to Manage Non-Blocking Sockets
e178. Accepting a Connection on a ServerSocketChannel
e179. Using a Selector to Manage Non-Blocking Server Sockets
e180. Detecting When a Non-Blocking Socket Is Closed by the Remote Host

See also: Byte Buffers    File Locking    Files    Streams   


© 2002 Addison-Wesley.