Package java.nio.channels

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


          SocketChannel sc = null;
          try {
            sc = SocketChannel.open();
            sc.configureBlocking(false);
            sc.socket().setTcpNoDelay(true);
            sc.connect(addr);
            sc.register(selector, SelectionKey.OP_CONNECT, client);
            client.connected_ = sc;
          } catch (SocketException se) {
            set.add(client);
            LOGGER.warning("unable to send new request: " +
View Full Code Here


                socket.bind( new InetSocketAddress(InetAddress.getByName(localHost), localPort) );
            }
            boolean success = false;
            try {
                channel.configureBlocking(false);
                channel.connect( new InetSocketAddress(InetAddress.getByName(remoteHost), remotePort) );
                context.getThread().select(channel, this, SelectionKey.OP_CONNECT);
                channel.finishConnect();
                success = true;
            } catch (NoRouteToHostException nrthe) {
                throw context.getRuntime().newErrnoEHOSTUNREACHError("SocketChannel.connect");
View Full Code Here

                ch.socket().bind( localAddress );
            }
   
            ch.configureBlocking( false );

            if( ch.connect( address ) )
            {
                SocketSession session = newSession( ch, handler );
                success = true;
                return session;
            }
View Full Code Here

                validateAddress(request.getRemoteAddress());
               
                if (request.getLocalAddress() != null) {
                    socketChannel.socket().bind(request.getLocalAddress());
                }
                socketChannel.connect(request.getRemoteAddress());
            } catch (IOException ex) {
                request.failed(ex);
                return;
            }
           
View Full Code Here

                if (request.getLocalAddress() != null) {
                    Socket sock = socketChannel.socket();
                    sock.setReuseAddress(HttpConnectionParams.getSoReuseaddr(this.params));
                    sock.bind(request.getLocalAddress());
                }
                boolean connected = socketChannel.connect(request.getRemoteAddress());
                if (connected) {
                    prepareSocket(socketChannel.socket());
                    ChannelEntry entry = new ChannelEntry(socketChannel, request);
                    addChannel(entry);
                    return;
View Full Code Here

                ch.socket().bind(localAddress);
            }

            ch.configureBlocking(false);

            if (ch.connect(address)) {
                DefaultConnectFuture future = new DefaultConnectFuture();
                newSession(ch, handler, config, future);
                success = true;
                return future;
            }
View Full Code Here

      log.finest("Setting up 'connect' channel for: "
        + isa.getAddress() + "/" + isa.getPort());
      SocketChannel sc = SocketChannel.open();
      sc.socket().setReceiveBufferSize(RECEIVE_BUFFER_SIZE);
      sc.configureBlocking(false);
      sc.connect(isa);
      sc.register(selector, SelectionKey.OP_CONNECT, al);
      break;
    default:
      log.warning("Unknown connection type: " + al.getConnectionType());
      break;
View Full Code Here

                if (request.getLocalAddress() != null) {
                    Socket sock = socketChannel.socket();
                    sock.setReuseAddress(HttpConnectionParams.getSoReuseaddr(this.params));
                    sock.bind(request.getLocalAddress());
                }
                boolean connected = socketChannel.connect(request.getRemoteAddress());
                if (connected) {
                    prepareSocket(socketChannel.socket());
                    ChannelEntry entry = new ChannelEntry(socketChannel, request);
                    addChannel(entry);
                    return;
View Full Code Here

                    final SocketChannel socketChannel = SocketChannel.open();
                    socketChannel.configureBlocking(false);

                    final InetSocketAddress address = new InetSocketAddress(host, port);

                    socketChannel.connect(address);

                    final Session session = new Session(socketChannel, address, uri);
                    session.ops(SelectionKey.OP_CONNECT);
                    session.trace("client");
                    connections.put(session.uri, session);
View Full Code Here

                validateAddress(request.getRemoteAddress());
               
                if (request.getLocalAddress() != null) {
                    socketChannel.socket().bind(request.getLocalAddress());
                }
                socketChannel.connect(request.getRemoteAddress());
            } catch (IOException ex) {
                request.failed(ex);
                return;
            }
           
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.