Package java.net

Examples of java.net.DatagramSocket.bind()


        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

                if (broadcast != null) socket.setBroadcast(broadcast.booleanValue());
                if (receiveBufferSize != null) socket.setReceiveBufferSize(receiveBufferSize.intValue());
                if (sendBufferSize != null) socket.setSendBufferSize(sendBufferSize.intValue());
                if (reuseAddress != null) socket.setReuseAddress(reuseAddress.booleanValue());
                if (trafficClass != null) socket.setTrafficClass(trafficClass.intValue());
                socket.bind(address);
                //noinspection unchecked
                final IoHandler<? super UdpChannel> handler = handlerFactory.createHandler();
                final NioUdpSocketChannelImpl udpSocketChannel = createChannel(datagramChannel, handler);
                final FutureUdpChannel futureUdpChannel = new FutureUdpChannel(udpSocketChannel, datagramChannel);
                boundChannels.add(udpSocketChannel);
View Full Code Here

    private static boolean isUdpPortAvailable(InetSocketAddress localAddress) {
        DatagramSocket ds = null;
        try {
            ds = new DatagramSocket(null);
            ds.setReuseAddress(false);
            ds.bind(localAddress);
            ds.close();
            ds = null;
            return true;
        } catch (Exception ignore) {
            // Unavailable
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.