Package java.nio.channels

Examples of java.nio.channels.SocketChannel.configureBlocking()


 
  @Override
  public void handleAccept(SelectionKey key) throws IOException {
    logger.debug("handle accept...");
    SocketChannel clientChannel = ((ServerSocketChannel) key.channel()).accept();
    clientChannel.configureBlocking(false);
    IOLoop.INSTANCE.addHandler(clientChannel, this, SelectionKey.OP_READ, ByteBuffer.allocate(READ_BUFFER_SIZE));
  }
 
  @Override
  public void handleConnect(SelectionKey key) throws IOException {
View Full Code Here


            ServerSocketChannel serverChannel = (ServerSocketChannel) key.channel();
            SocketChannel socketChannel = serverChannel.accept();
            if(LOG.isDebugEnabled()) {
                LOG.debug("accepted a connection from " + socketChannel.socket().getInetAddress());
            }
            socketChannel.configureBlocking(false);
            socketChannel.register(key.selector(), SelectionKey.OP_READ, nextHandler);
        }

    }
View Full Code Here

    private static SocketChannel createSocketChannel(final SocketAddress sockAddr, final boolean blocking, final int rcvbufSize) {
        final SocketChannel ch;
        try {
            ch = SocketChannel.open();
            ch.configureBlocking(blocking);
        } catch (IOException e) {
            LOG.error("Failed to open SocketChannel.", e);
            throw new IllegalStateException(e);
        }
        final Socket sock = ch.socket();
View Full Code Here

      SocketChannel socketChannel = selector.provider().openSocketChannel();
      Socket socket = socketChannel.socket();
      socket.setTcpNoDelay(true);
      socket.setTrafficClass(IPTOS_LOWDELAY);
      socket.connect(remoteAddress, timeout); // Connect using blocking mode for simplicity.
      socketChannel.configureBlocking(false);
      this.socketChannel = socketChannel;

      selectionKey = socketChannel.register(selector, SelectionKey.OP_READ);
      selectionKey.attach(this);
View Full Code Here

  outgoing()
  {
    try{     
      final SocketChannel  channel = SocketChannel.open();
     
      channel.configureBlocking( false );
   
      if ( channel.connect( new InetSocketAddress("localhost", 8765 ))){
             
        outgoing( channel );
       
View Full Code Here

       
          socket_channel.close();
         
        }else{
           
          socket_channel.configureBlocking(false);
 
          AEProxyConnectionImpl processor = new AEProxyConnectionImpl(this, socket_channel, proxy_handler);
         
          if ( !processor.isClosed()){
           
View Full Code Here

        while (i.hasNext()) {
            SelectionKey key = (SelectionKey) i.next();
            if (key.isAcceptable()) {
                ServerSocketChannel ssc = (ServerSocketChannel) key.channel();
                SocketChannel sc = ssc.accept();
                sc.configureBlocking(false);
                sc.register(this.selector, SelectionKey.OP_READ);
            } else if (key.isReadable()) {
                SocketChannel sc = (SocketChannel) key.channel();
                ByteBuffer buffer = ByteBuffer.allocate(10);
                buffer.clear();
View Full Code Here

    // channel.
    ServerSocketChannel serverSocketChannel = (ServerSocketChannel) key.channel();

    // Accept the connection and make it non-blocking
    SocketChannel socketChannel = serverSocketChannel.accept();
    socketChannel.configureBlocking(false);

    // Register the new SocketChannel with our Selector, indicating
    // we'd like to be notified when there's data waiting to be read
    socketChannel.register(this.selector, SelectionKey.OP_READ);
View Full Code Here

    private void handleAccept() throws IOException {
        // new incoming connection
        SocketChannel client = this.server.accept();

        // Non blocking client
        client.configureBlocking(false);

        // Register client (with an empty channel attachment)
        client.register(this.selector, SelectionKey.OP_READ, new ChannelAttachment());
    }
View Full Code Here

                                cChannel.socket().setReuseAddress( true );
                                cChannel.socket().setSoLinger( false, 0 );
                               
                                // ensure that the socket channel is prepared
                                // for non-blocking operations
                                cChannel.configureBlocking( false );
                                // create a new ConnectionHeader for all
                                // upcoming operations on the
                                // accepted socket connection
                                header = new ConnectionHeader( cChannel, cChannel.socket().getRemoteSocketAddress()
                                        .toString(), true );
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.