Code example for ServerSocketChannel

Methods: registersocketconfigureBlocking

0
     
    public Listener() throws IOException { 
      address = new InetSocketAddress(bindAddress, port);
      // Create a new server socket and set to non blocking mode 
      acceptChannel = ServerSocketChannel.open();
      acceptChannel.configureBlocking(false);
 
      // Bind the server socket to the local host and port 
      bind(acceptChannel.socket(), address, backlogLength);
      port = acceptChannel.socket().getLocalPort(); //Could be an ephemeral port
      // create a selector; 
      selector= Selector.open();
 
      // Register accepts on the server socket with the selector. 
      acceptChannel.register(selector, SelectionKey.OP_ACCEPT);
      this.setName("IPC Server listener on " + port);
      this.setDaemon(true);
    } 
    /** cleanup connections from connectionList. Choose a random range 
     * to scan and also have a limit on the number of the connections 
Experience pair programming with AI  Get Codota for Java