Package java.net

Examples of java.net.Socket.bind()


                sock = socket;
            } else {
                sock = createSocket(context);
            }
            if (localAddress != null) {
                sock.bind(localAddress);
            }
            try {
                sock.connect(remoteAddress, connectTimeout);
            } catch (SocketTimeoutException ex) {
                throw new ConnectTimeoutException(ex, host, remoteAddress.getAddress());
View Full Code Here


        if (sock == null) {
            sock = createSocket();
        }
        if (localAddress != null) {
            sock.setReuseAddress(HttpConnectionParams.getSoReuseaddr(params));
            sock.bind(localAddress);
        }
        int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
        int soTimeout = HttpConnectionParams.getSoTimeout(params);

        try {
View Full Code Here

            throw new IllegalArgumentException("HTTP parameters may not be null");
        }
        Socket sock = socket != null ? socket : this.socketfactory.createSocket();
        if (localAddress != null) {
            sock.setReuseAddress(HttpConnectionParams.getSoReuseaddr(params));
            sock.bind(localAddress);
        }

        int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
        int soTimeout = HttpConnectionParams.getSoTimeout(params);
View Full Code Here

                    addr.convertToString().toString(), RubyNumeric.fix2int(port));

            Channel socketChannel = getChannel();
            if (socketChannel instanceof SocketChannel) {
                Socket socket = ((SocketChannel)socketChannel).socket();
                socket.bind(iaddr);
            } else if (socketChannel instanceof DatagramChannel) {
                DatagramSocket socket = ((DatagramChannel)socketChannel).socket();
                socket.bind(iaddr);
            } else {
                throw getRuntime().newErrnoENOPROTOOPTError();
View Full Code Here

            if (socketChannel instanceof SocketChannel) {
                Socket socket = ((SocketChannel)socketChannel).socket();
                socket.bind(iaddr);
            } else if (socketChannel instanceof DatagramChannel) {
                DatagramSocket socket = ((DatagramChannel)socketChannel).socket();
                socket.bind(iaddr);
            } else {
                throw getRuntime().newErrnoENOPROTOOPTError();
            }
        } catch(UnknownHostException e) {
            throw sockerr(context.getRuntime(), "bind(2): unknown host");
View Full Code Here

            // This is a bit convoluted because (1) SocketChannel.bind is only in jdk 7 and
            // (2) Socket.getChannel() seems to return null in some cases
            final SocketChannel channel = SocketChannel.open();
            final Socket socket = channel.socket();
            if (localHost != null) {
                socket.bind( new InetSocketAddress(InetAddress.getByName(localHost), localPort) );
            }
            boolean success = false;
            try {
                channel.configureBlocking(false);
                channel.connect( new InetSocketAddress(InetAddress.getByName(remoteHost), remotePort) );
View Full Code Here

                validateAddress(request.getRemoteAddress());

                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);
View Full Code Here

  public void testAvoidLoopbackTcpSockets() throws Exception {
    Configuration conf = new Configuration();

    Socket socket = NetUtils.getDefaultSocketFactory(conf)
      .createSocket();
    socket.bind(new InetSocketAddress("127.0.0.1", 0));
    System.err.println("local address: " + socket.getLocalAddress());
    System.err.println("local port: " + socket.getLocalPort());
    try {
      NetUtils.connect(socket,
        new InetSocketAddress(socket.getLocalAddress(), socket.getLocalPort()),
View Full Code Here

            throw new IllegalArgumentException("HTTP parameters may not be null");
        }
        Socket sock = socket != null ? socket : this.socketfactory.createSocket();
        if (localAddress != null) {
            sock.setReuseAddress(HttpConnectionParams.getSoReuseaddr(params));
            sock.bind(localAddress);
        }

        int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
        int soTimeout = HttpConnectionParams.getSoTimeout(params);
View Full Code Here

        this.localTimeRenew = localTimeRenew;
        Socket s;
        for (InetSocketAddress participant : participants) {
            s = new Socket();
            try {
                s.bind(participant);
                if (address == null) {
                    address = participant;
                } else if (!address.equals(participant)) {
                    participants.add(participant);
                }
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.