Package java.nio.channels

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


                throw new IllegalStateException(e);
            }
        }
        final boolean connected;
        try {
            connected = ch.connect(sockAddr);
        } catch (IOException e) {
            LOG.error("Failed to connect socket: " + sockAddr, e);
            throw new IllegalStateException(e);
        }
        if(!connected) {
View Full Code Here


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

            throw new IllegalStateException("Cannot open a channel", e);
        }

        // Connect
        try {
            channel.connect(this.socketAddress);
        } catch (IOException e) {
            cleanChannel(channel);
            throw new IllegalStateException("Cannot connect the channel", e);
        }
View Full Code Here

    }
   
    else if(session.getClass() == ClientIoSession.class) {  //注册连接操作
      ClientIoSession clientIoSession = (ClientIoSession) session;
      SelectionKey selectKey = channel.register(selector, SelectionKey.OP_CONNECT, session);
      channel.connect(clientIoSession.getConnectAddress());
      session.setSelectionKey(selectKey);
    }
   
    //开启定时检查
    session.lastAccessTime = System.currentTimeMillis();
View Full Code Here

    }
    getLogger().log(Level.FINE, "opening port " + port);
    SocketAddress address = new InetSocketAddress("localhost",port);
    SocketChannel channel = SocketChannel.open();
    channel.configureBlocking(false);
    if (! channel.connect(address)) {
      // we're willing to wait for about a second.
      for (int i = 0; (! channel.finishConnect()) && i < 4; i++) {
  try {
    getLogger().log(Level.FINE, "not connected; sleeping (" + i + ").");
    Thread.currentThread().sleep(250);
View Full Code Here

        try
        {
            SocketChannel sc = SocketChannel.open();
            //        SocketChannel sc = (SocketChannel)GetChannel();
            sc.configureBlocking(false);
            if (!sc.connect(isa))
            {
                SetConnecting();
            }
            else
            {
View Full Code Here

        // connect to a running server. We get an immediate result if
        // the socket is blocking, and either true or false if it's non blocking
        boolean connected;
        try {
            connected = clientSocket.connect(remoteAddress);
        } catch (IOException e) {
            ConnectFuture future = new ConnectFuture();
            future.cannotConnect(e);
            return future;
        }
View Full Code Here

            // prepare the handler for the connection
            client = CTPConnection.client(host, selectionKey, handler, connectionManager);
            selectionKey.attach(client);

            // connect (non-blocking)
            channel.connect(address);

        } catch(IOException e) {
            handler.connectionClosed(client, e);
        }
    }
View Full Code Here

    public void startConnection( HttpDestination destination )
        throws IOException
    {
        SocketChannel channel = SocketChannel.open();
        Address address = destination.isProxied() ? destination.getProxy() : destination.getAddress();
        channel.connect(address.toSocketAddress());
        channel.configureBlocking( false );
        channel.socket().setSoTimeout( _httpClient.getSoTimeout());
        _selectorManager.register( channel, destination );
    }
View Full Code Here

        int attempts = 0;
        while (true)
        {
            try
            {
                channel.connect(new InetSocketAddress(to, DatabaseDescriptor.getStoragePort()));
                // success
                return channel;
            }
            catch (IOException e)
            {
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.