Package java.net

Examples of java.net.ServerSocket.bind()


        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


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

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

        ServerSocket serverSocket = new ServerSocket();
        assertFalse("Socket indicated bound when it should be (1)",
                serverSocket.isBound());

        // now bind and validate bound ok
        serverSocket.bind(new InetSocketAddress(addr, 0));
        assertTrue("Socket indicated  not bound when it should be (1)",
                serverSocket.isBound());
        serverSocket.close();

        // now do with some of the other constructors
View Full Code Here

            // set up server and connect
            InetSocketAddress anyAddress = new InetSocketAddress(InetAddress
                    .getLocalHost(), 0);
            ServerSocket serverSocket = new ServerSocket();
            serverSocket.setReuseAddress(false);
            serverSocket.bind(anyAddress);
            SocketAddress theAddress = serverSocket.getLocalSocketAddress();

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

            // the platform to determine what the expected result is.
            String platform = System.getProperty("os.name");
            try {
                serverSocket = new ServerSocket();
                serverSocket.setReuseAddress(false);
                serverSocket.bind(theAddress);
                if ((!platform.startsWith("Windows"))) {
                    fail("No exception when setReuseAddress is false and we bind:"
                            + theAddress.toString());
                }
            } catch (IOException ex) {
View Full Code Here

            // now test case were we set it to true
            anyAddress = new InetSocketAddress(InetAddress.getLocalHost(), 0);
            serverSocket = new ServerSocket();
            serverSocket.setReuseAddress(true);
            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

            // 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

        client = new Socket();
        assertFalse("Socket indicated bound when it was not (2)", client
                .isBound());

        server = new ServerSocket();
        server.bind(new InetSocketAddress(InetAddress.getLocalHost(), 0));
        InetSocketAddress boundAddress = new InetSocketAddress(server
                .getInetAddress(), server.getLocalPort());
        client.connect(boundAddress);
        worker = server.accept();
        assertTrue("Socket indicated not bound when it should be (2)", client
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.