Code example for ServerSocketChannel

Methods: configureBlocking, register, socket

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