Package java.nio.channels

Examples of java.nio.channels.ServerSocketChannel.register()


            try
            {
                ssc = ServerSocketChannel.open();
                ssc.configureBlocking( false );
                ssc.socket().bind( req.address, req.backlog );
                ssc.register( selector, SelectionKey.OP_ACCEPT, req );

                channels.put( req.address, ssc );
            }
            catch( IOException e )
            {
View Full Code Here


    public SocketAddress listen(
            final SocketAddress address) throws IOException {
        ServerSocketChannel serverChannel = ServerSocketChannel.open();
        serverChannel.configureBlocking(false);
        serverChannel.socket().bind(address);
        SelectionKey key = serverChannel.register(this.selector, SelectionKey.OP_ACCEPT);
        key.attach(null);
        return serverChannel.socket().getLocalSocketAddress();
    }

    public void shutdown() throws IOException {
View Full Code Here

      // host-port 7935
      serverSocketChannel.socket().bind(new java.net.InetSocketAddress(KorusRuntime.getJavaPort()));
      // Create the selector
      Selector selector = Selector.open();
      // Recording server to selector (type OP_ACCEPT)
      serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT);

      // Infinite server loop
      for (;;)
      {
View Full Code Here

                } else {
                    return;
                }
            }
            try {
                SelectionKey key = serverChannel.register(this.selector, SelectionKey.OP_ACCEPT);
                key.attach(request);
                request.setKey(key);
            } catch (IOException ex) {
                throw new IOReactorException("Failure registering channel " +
                        "with the selector", ex);
View Full Code Here

    InetSocketAddress isa = null;
    while ((isa = waiting_accept.poll()) != null) {
      ServerSocketChannel ssc = ServerSocketChannel.open();
      ssc.configureBlocking(false);
      ssc.socket().bind(isa);
      ssc.register(clientSel, SelectionKey.OP_ACCEPT, null);
    } // end of while (isa = waiting_accept.poll() != null)
  }

  // Implementation of java.lang.Runnable
View Full Code Here

      log.finest("Setting up 'accept' channel...");
      ServerSocketChannel ssc = ServerSocketChannel.open();
      ssc.socket().setReceiveBufferSize(RECEIVE_BUFFER_SIZE);
      ssc.configureBlocking(false);
      ssc.socket().bind(isa);
      ssc.register(selector, SelectionKey.OP_ACCEPT, al);
      break;
    case connect:
      log.finest("Setting up 'connect' channel for: "
        + isa.getAddress() + "/" + isa.getPort());
      SocketChannel sc = SocketChannel.open();
View Full Code Here

           
            // and bind.
            socket.bind(localAddress, getBacklog());
           
            // Register the channel within the selector for ACCEPT event
            channel.register(selector, SelectionKey.OP_ACCEPT);
            success = true;
        } finally {
            if (!success) {
                close(channel);
            }
View Full Code Here

        this.port = serverSocket.getLocalPort();
        me = URI.create("conn://" + this.host + ":" + this.port);

        selector = Selector.open();

        serverChannel.register(selector, SelectionKey.OP_ACCEPT);

        println("Listening");
    }

    public int getPort() {
View Full Code Here

    public SocketAddress listen(
            final SocketAddress address) throws IOException {
        ServerSocketChannel serverChannel = ServerSocketChannel.open();
        serverChannel.configureBlocking(false);
        serverChannel.socket().bind(address);
        SelectionKey key = serverChannel.register(this.selector, SelectionKey.OP_ACCEPT);
        key.attach(null);
        return serverChannel.socket().getLocalSocketAddress();
    }

    public void shutdown() throws IOException {
View Full Code Here

        // set the port the server channel will listen to
        serverSocket.bind (new InetSocketAddress (getBind(),getTcpListenPort()));
        // set non-blocking mode for the listening socket
        serverChannel.configureBlocking (false);
        // register the ServerSocketChannel with the Selector
        serverChannel.register (selector, SelectionKey.OP_ACCEPT);
        while (doListen && selector != null) {
            // this may block for a long time, upon return the
            // selected set contains keys of the ready channels
            try {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.