Package java.net

Examples of java.net.Socket.bind()


        theAddress = new InetSocketAddress(InetAddress.getLocalHost(), 0);
        theSocket.bind(theAddress);

        Socket theSocket2 = new Socket();
        try {
            theSocket2.bind(theSocket.getLocalSocketAddress());
            fail("No exception binding to address that is not available");
        } catch (IOException ex) {
            // Expected
        }
        theSocket.close();
View Full Code Here


        Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(
                "127.0.0.1", 0));
        Socket socket = new Socket(proxy);

        InetAddress address = InetAddress.getByName("localhost");
        socket.bind(new InetSocketAddress(address, 0));

        assertEquals(address, socket.getLocalAddress());
        assertTrue(0 != socket.getLocalPort());

        socket.close();
View Full Code Here

                .getProperty("java.net.preferIPv4Stack");
        String preferIPv6AddressesValue = System
                .getProperty("java.net.preferIPv6Addresses");

        client = new Socket();
        client.bind(new InetSocketAddress(InetAddress.getByName("0.0.0.0"), 0));

        if (((preferIPv4StackValue == null) || preferIPv4StackValue
                .equalsIgnoreCase("false"))
                && (preferIPv6AddressesValue != null)
                && (preferIPv6AddressesValue.equals("true"))) {
View Full Code Here

        assertNull(
                "Returned incorrect InetSocketAddress -unbound socket- Expected null",
                client.getLocalSocketAddress());

        // now bind the socket and make sure we get the right answer
        client.bind(new InetSocketAddress(InetAddress.getLocalHost(), 0));
        clientPort = client.getLocalPort();
        assertEquals("Returned incorrect InetSocketAddress(2):",
                new InetSocketAddress(InetAddress.getLocalHost(), clientPort),
                client.getLocalSocketAddress());
        client.close();
View Full Code Here

                client.getLocalSocketAddress());
        client.close();

        // now validate the behaviour when the any address is returned
        client = new Socket();
        client.bind(new InetSocketAddress(InetAddress.getByName("0.0.0.0"), 0));

        String preferIPv4StackValue = System
                .getProperty("java.net.preferIPv4Stack");
        String preferIPv6AddressesValue = System
                .getProperty("java.net.preferIPv6Addresses");
View Full Code Here

        }
        client.close();

        // now validate the same for getLocalAddress
        client = new Socket();
        client.bind(new InetSocketAddress(InetAddress.getByName("0.0.0.0"), 0));
        if (((preferIPv4StackValue == null) || preferIPv4StackValue
                .equalsIgnoreCase("false"))
                && (preferIPv6AddressesValue != null)
                && (preferIPv6AddressesValue.equals("true"))) {
            assertTrue(
View Full Code Here

        "Returned incorrect InetSocketAddress -unbound socket- Expected null",
        theSocket.getLocalSocketAddress());

    // now bind the socket and make sure we get the right answer
    portNumber = Support_PortManager.getNextPort();
    theSocket.bind(new InetSocketAddress(InetAddress.getLocalHost(),
        portNumber));
    assertTrue(
        "Returned incorrect InetSocketAddress(2):"
            + theSocket.getLocalSocketAddress().toString()
            + "Expected: "
View Full Code Here

    // now create one that is not connect and validate that we get the
    // right answer
    Socket theSocket = new Socket();
    portNumber = Support_PortManager.getNextPort();
    theSocket.bind(new InetSocketAddress(InetAddress.getLocalHost(),
        portNumber));

    assertNull("Returned incorrect InetSocketAddress -unconnected socket:"
        + "Expected: NULL", theSocket.getRemoteSocketAddress());
View Full Code Here

    }

    // Address we cannot bind to
    Socket theSocket = new Socket();
    try {
      theSocket.bind(new InetSocketAddress(InetAddress
          .getByAddress(Support_Configuration.nonLocalAddressBytes),
          Support_PortManager.getNextPort()));
      fail("No exception when binding to bad address:"
             + theSocket.getLocalSocketAddress().toString());
    } catch (IOException ex) {
View Full Code Here

    theSocket.close();

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

    // validate that the localSocketAddress reflects the address we
    // bound to
    assertTrue(
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.