Code example for ServerSocketChannel

Methods: configureBlocking, register, socket

    protected void bind() throws IOException { 
        // allocate an unbound server socket channel 
        serverChannel =;
        // Get the associated ServerSocket to bind it with 
        ServerSocket serverSocket = serverChannel.socket();
        // create a new Selector for use below 
        selector =;
        // set the port the server channel will listen to 
        //serverSocket.bind(new InetSocketAddress(getBind(), getTcpListenPort())); 
        // set non-blocking mode for the listening socket 
        // register the ServerSocketChannel with the Selector 
        serverChannel.register(selector, SelectionKey.OP_ACCEPT);
    public void addEvent(Runnable event) {
        if ( selector != null ) {
            synchronized (events) {