Package java.net

Examples of java.net.ServerSocket.bind()


        client = new Socket();
        assertFalse("Socket indicated connected when it was not", client
                .isConnected());

        server = new ServerSocket();
        server.bind(theAddress);
        InetSocketAddress boundAddress = new InetSocketAddress(server
                .getInetAddress(), server.getLocalPort());
        client.connect(boundAddress);
        worker = server.accept();
        assertTrue("Socket indicated  not connected when it should be", client
View Full Code Here


        // Make sure we can now connect and that connections appear to come
        // from the address we bound to.
        InetSocketAddress theAddress = new InetSocketAddress(InetAddress
                .getLocalHost(), 0);
        ServerSocket server = new ServerSocket();
        server.bind(theAddress);
        int sport = server.getLocalPort();
        InetSocketAddress boundAddress = new InetSocketAddress(InetAddress
                .getLocalHost(), sport);

        theSocket.connect(boundAddress);
View Full Code Here

        ServerSocketChannel theServerChannel = ServerSocketChannel.open();
        ServerSocket serversocket = theServerChannel.socket();
        serversocket.setReuseAddress(true);
        // Bind the socket
        serversocket.bind(address);

        boolean doneNonBlockingConnect = false;
        // Loop so that we make sure we're definitely testing finishConnect()
        while (!doneNonBlockingConnect) {
            channel1 = SocketChannel.open();
View Full Code Here

        // Get the associated ServerSocket to bind it with
        ServerSocket serverSocket = serverChannel.socket();
        // create a new Selector for use below
        Selector selector = Selector.open();
        // set the port the server channel will listen to
        serverSocket.bind (new InetSocketAddress (bind,tcpListenPort));
        // set non-blocking mode for the listening socket
        serverChannel.configureBlocking (false);
        // register the ServerSocketChannel with the Selector
        serverChannel.register (selector, SelectionKey.OP_ACCEPT);
        while (doListen) {
View Full Code Here

    int socketWriteTimeout = conf.getInt(DFSConfigKeys.DFS_DATANODE_SOCKET_WRITE_TIMEOUT_KEY,
        HdfsServerConstants.WRITE_TIMEOUT);
   
    ServerSocket ss = (socketWriteTimeout > 0) ?
        ServerSocketChannel.open().socket() : new ServerSocket();
    ss.bind(streamingAddr, 0);
   
    // Check that we got the port we need
    if (ss.getLocalPort() != streamingAddr.getPort()) {
      throw new RuntimeException("Unable to bind on specified streaming port in secure " +
          "context. Needed " + streamingAddr.getPort() + ", got " + ss.getLocalPort());
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

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.