Package java.net

Examples of java.net.ServerSocket.bind()


            // now try to rebind the server which should pass with
            // setReuseAddress to true
            try {
                serverSocket = new ServerSocket();
                serverSocket.setReuseAddress(true);
                serverSocket.bind(theAddress);
            } catch (IOException ex) {
                fail("Unexpected exception when setReuseAddress is true and we bind:"
                        + theAddress.toString() + ":" + ex.toString());
            }
            stillActiveSocket.close();
View Full Code Here


            // now test default case were we expect this to work regardless of
            // the value set
            anyAddress = new InetSocketAddress(InetAddress.getLocalHost(), 0);
            serverSocket = new ServerSocket();
            serverSocket.bind(anyAddress);
            theAddress = serverSocket.getLocalSocketAddress();

            // make a connection to the server, then close the server
            theSocket = new Socket();
            theSocket.connect(theAddress);
View Full Code Here

            serverSocket.close();

            // now try to rebind the server which should pass
            try {
                serverSocket = new ServerSocket();
                serverSocket.bind(theAddress);
            } catch (IOException ex) {
                fail("Unexpected exception when setReuseAddress is the default case and we bind:"
                        + theAddress.toString() + ":" + ex.toString());
            }
            stillActiveSocket.close();
View Full Code Here

        }
        // create servers socket, bind it and then validate basic state
        ServerSocket theSocket = new ServerSocket();
        InetSocketAddress theAddress = new InetSocketAddress(InetAddress
                .getLocalHost(), 0);
        theSocket.bind(theAddress);
        int portNumber = theSocket.getLocalPort();
        assertTrue(
                "Returned incorrect InetSocketAddress(2):"
                        + theSocket.getLocalSocketAddress().toString()
                        + "Expected: "
View Full Code Here

        clientSocket.close();

        // validate we can specify null for the address in the bind and all
        // goes ok
        theSocket = new ServerSocket();
        theSocket.bind(null);
        theSocket.close();

        // Address that we have already bound to
        theSocket = new ServerSocket();
        ServerSocket theSocket2 = new ServerSocket();
View Full Code Here

        ServerSocket theSocket2 = new ServerSocket();
        try {
            theAddress = new InetSocketAddress(InetAddress.getLocalHost(), 0);
            theSocket.bind(theAddress);
            SocketAddress localAddress = theSocket.getLocalSocketAddress();
            theSocket2.bind(localAddress);
            fail("No exception binding to address that is not available");
        } catch (IOException ex) {
        }
        theSocket.close();
        theSocket2.close();
View Full Code Here

        // create servers socket, bind it and then validate basic state
        ServerSocket theSocket = new ServerSocket();
        InetSocketAddress theAddress = new InetSocketAddress(InetAddress
                .getLocalHost(), 0);
        theSocket.bind(theAddress, 5);
        int portNumber = theSocket.getLocalPort();
        assertTrue(
                "Returned incorrect InetSocketAddress(2):"
                        + theSocket.getLocalSocketAddress().toString()
                        + "Expected: "
View Full Code Here

        clientSocket.close();

        // validate we can specify null for the address in the bind and all
        // goes ok
        theSocket = new ServerSocket();
        theSocket.bind(null, 5);
        theSocket.close();

        // Address that we have already bound to
        theSocket = new ServerSocket();
        ServerSocket theSocket2 = new ServerSocket();
View Full Code Here

        ServerSocket theSocket2 = new ServerSocket();
        try {
            theAddress = new InetSocketAddress(InetAddress.getLocalHost(), 0);
            theSocket.bind(theAddress, 5);
            SocketAddress inuseAddress = theSocket.getLocalSocketAddress();
            theSocket2.bind(inuseAddress, 5);
            fail("No exception binding to address that is not available");
        } catch (IOException ex) {
            // expected
        }
        theSocket.close();
View Full Code Here

        .getLocalHost(), Support_PortManager.getNextPort());
    theSocket = new Socket();
    assertFalse("Socket indicated bound when it was not (2)", theSocket
        .isBound());
    serverSocket = new ServerSocket();
    serverSocket.bind(theAddress);
    theSocket.connect(theAddress);
    servSock = serverSocket.accept();
    assertTrue("Socket indicated not bound when it should be (2)",
        theSocket.isBound());
    theSocket.close();
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.