Package java.net

Examples of java.net.Socket.bind()


    final int tms = getTimeout() > 0 ? getTimeout() * 1000 : 0;
    final int port = uri.getPort() > 0 ? uri.getPort() : GIT_PORT;
    final Socket s = new Socket();
    try {
      final InetAddress host = InetAddress.getByName(uri.getHost());
      s.bind(null);
      s.connect(new InetSocketAddress(host, port), tms);
    } catch (IOException c) {
      try {
        s.close();
      } catch (IOException closeErr) {
View Full Code Here


        }

        @Override
        public Socket createSocket(final InetAddress address, final int port, final InetAddress localAddress, final int localPort) throws IOException {
            final Socket socket = createSocket();
            socket.bind(new InetSocketAddress(localAddress, localPort));
            socket.connect(new InetSocketAddress(address, port));
            return socket;
        }

        @Override
View Full Code Here

        }

        @Override
        public Socket createSocket(final String name, final InetAddress address, final int port, final InetAddress localAddress, final int localPort) throws IOException {
            final Socket socket = createSocket(name);
            socket.bind(new InetSocketAddress(localAddress, localPort));
            socket.connect(new InetSocketAddress(address, port));
            return socket;
        }

    }
View Full Code Here

        final ConnectionImpl connection = new ConnectionImpl(socket, messageHandler, readExecutor, callback);
        final Thread thread = threadFactory.newThread(connection.getReadTask());
        if (thread == null) {
            throw MESSAGES.threadCreationRefused();
        }
        if (bindAddress != null) socket.bind(bindAddress);
        if (readTimeout != 0) socket.setSoTimeout(readTimeout);
        socket.connect(serverAddress, connectTimeout);
        thread.setName("Read thread for " + serverAddress);
        thread.start();
        CLIENT_LOGGER.tracef("Connected to %s", serverAddress);
View Full Code Here

        final Socket socket = socketFactory.createSocket(this.name);
        // if the outbound binding specifies the source to use, then bind this socket to the
        // appropriate source
        final SocketAddress sourceSocketAddress = this.getOptionalSourceSocketAddress();
        if (sourceSocketAddress != null) {
            socket.bind(sourceSocketAddress);
        }
        return socket;
    }

    private SocketAddress getOptionalSourceSocketAddress() {
View Full Code Here

        client.close();

        // now create one that is not connected and validate that we get the
        // right answer
        Socket theSocket = new Socket();
        theSocket.bind(new InetSocketAddress(InetAddress.getLocalHost(), 0));
        assertNull("Returned incorrect InetSocketAddress -unconnected socket:",
                theSocket.getRemoteSocketAddress());

        // now connect and validate we get the right answer
        theSocket.connect(new InetSocketAddress(InetAddress.getLocalHost(),
View Full Code Here

        try {
            Socket theSocket = new Socket();
            theSocket.setReuseAddress(false);
            // Bind to any available port on the given address
            theSocket
                    .bind(new InetSocketAddress(InetAddress.getLocalHost(), 0));
            InetSocketAddress localAddress1 = new InetSocketAddress(theSocket
                    .getLocalAddress(), theSocket.getLocalPort());

            Socket theSocket2 = new Socket();
View Full Code Here

             * Try to invoke a bind while the port is busy (TIME_WAIT). Note
             * that we may not succeed, which will cause the test to pass
             * without testing the reuseaddr behavior.
             */
            theSocket.close();
            theSocket2.bind(localAddress1);

            theSocket2.close();

            ensureExceptionThrownIfOptionIsUnsupportedOnOS(SO_REUSEADDR);
        } catch (Exception e) {
View Full Code Here

        // Address we cannot bind to
        Socket theSocket = new Socket();
        InetSocketAddress bogusAddress = new InetSocketAddress(InetAddress
                .getByAddress(Support_Configuration.nonLocalAddressBytes), 42);
        try {
            theSocket.bind(bogusAddress);
            fail("No exception when binding to bad address");
        } catch (IOException ex) {
            // Expected
        }
        theSocket.close();
View Full Code Here

        }
        theSocket.close();

        // Now create a socket that is not bound and then bind it
        theSocket = new Socket();
        theSocket.bind(new InetSocketAddress(InetAddress.getLocalHost(), 0));
        int portNumber = theSocket.getLocalPort();

        // Validate that the localSocketAddress reflects the address we
        // bound to
        assertEquals("Local address not correct after bind",
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.