Package java.net

Examples of java.net.DatagramSocket.bind()


        // now make sure that datagrams sent from this socket appear to come
        // from the address we bound to
        InetAddress localHost = InetAddress.getLocalHost();
        portNumber = ports[2];
        DatagramSocket ds = new DatagramSocket(null);
        ds.bind(new InetSocketAddress(localHost, portNumber));

        server = new DatagramServer(serverPortNumber, localHost);
        server.start();
        Thread.sleep(1000);
View Full Code Here


        DatagramSocket theSocket2 = new DatagramSocket(ports[0]);
        try {
            InetSocketAddress theAddress = new InetSocketAddress(InetAddress
                    .getLocalHost(), ports[1]);
            theSocket.bind(theAddress);
            theSocket2.bind(theAddress);
            fail("No exception binding to address that is not available");
        } catch (SocketException ex) {
        }
        theSocket.close();
        theSocket2.close();
View Full Code Here

        InetSocketAddress theLocalAddress = new InetSocketAddress(InetAddress
                .getLocalHost(), ports[2]);
        theSocket = new DatagramSocket(null);
        assertFalse("Socket indicated bound when it should not be (2)",
                theSocket.isBound());
        theSocket.bind(theLocalAddress);
        assertTrue("Socket indicated not bound when it should be (4)",
                theSocket.isBound());
        theSocket.close();
        assertTrue("Socket indicated not bound when it should be (5)",
                theSocket.isBound());
View Full Code Here

        // now create one that is not connected and validate that we get the
        // right answer
        DatagramSocket theSocket = new DatagramSocket(null);
        portNumber = ports[2];
        theSocket.bind(new InetSocketAddress(InetAddress.getLocalHost(),
                portNumber));
        assertNull("Returned incorrect InetSocketAddress -unconnected socket:"
                + "Expected: NULL", theSocket.getRemoteSocketAddress());

        // now connect and validate we get the right answer
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.getNextPortForUDP();
        theSocket.bind(new InetSocketAddress(InetAddress.getLocalHost(),
                portNumber));
        assertTrue(
                "Returned incorrect InetSocketAddress(2):"
                        + theSocket.getLocalSocketAddress().toString()
                        + "Expected: "
View Full Code Here

                theSocket1 = new DatagramSocket(null);
                theSocket2 = new DatagramSocket(null);
                theSocket1.setReuseAddress(false);
                theSocket2.setReuseAddress(false);
                theSocket1.bind(theAddress);
                theSocket2.bind(theAddress);
                fail("No exception when trying to connect to do duplicate socket bind with re-useaddr set to false");
            } catch (BindException e) {

            }
            if (theSocket1 != null)
View Full Code Here

            theSocket1 = new DatagramSocket(null);
            theSocket2 = new DatagramSocket(null);
            theSocket1.setReuseAddress(true);
            theSocket2.setReuseAddress(true);
            theSocket1.bind(theAddress);
            theSocket2.bind(theAddress);

            if (theSocket1 != null)
                theSocket1.close();
            if (theSocket2 != null)
                theSocket2.close();
View Full Code Here

                theAddress = new InetSocketAddress(InetAddress.getLocalHost(),
                        Support_PortManager.getNextPortForUDP());
                theSocket1 = new DatagramSocket(null);
                theSocket2 = new DatagramSocket(null);
                theSocket1.bind(theAddress);
                theSocket2.bind(theAddress);
                fail("No exception when trying to connect to do duplicate socket bind with re-useaddr left as default");
            } catch (BindException e) {

            }
            if (theSocket1 != null)
View Full Code Here

                // now create one that is not connected and validate that we get the
                // right answer
                DatagramSocket theSocket = new DatagramSocket(null);
                portNumber = ports[2];
                theSocket.bind(new InetSocketAddress(InetAddress.getLocalHost(),
                                portNumber));
                assertNull(
                                "Returned incorrect InetSocketAddress -unconnected socket:"
                                                + "Expected: NULL", theSocket
                                                .getRemoteSocketAddress());
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.getNextPortForUDP();
                theSocket.bind(new InetSocketAddress(InetAddress.getLocalHost(),
                                portNumber));
                assertTrue("Returned incorrect InetSocketAddress(2):"
                                + theSocket.getLocalSocketAddress().toString()
                                + "Expected: "
                                + (new InetSocketAddress(InetAddress.getLocalHost(),
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.