Package java.net

Examples of java.net.DatagramSocket.connect()


        assertEquals("Expected -1 for remote port as not connected", -1,
                theSocket.getPort());

        // Now connect the socket and validate that we get the right port
        int portNumber = 49152; // any valid port, even if it is unreachable
        theSocket.connect(InetAddress.getLocalHost(), portNumber);
        assertEquals("getPort returned wrong value", portNumber, theSocket
                .getPort());
    }

    /**
 
View Full Code Here


        server = new DatagramServer(serverPortNumber, localHost);
        server.start();
        Thread.sleep(1000);

        ds.connect(new InetSocketAddress(localHost, serverPortNumber));

        byte[] sendBytes = { 'T', 'e', 's', 't', 0 };
        DatagramPacket send = new DatagramPacket(sendBytes, sendBytes.length);
        ds.send(send);
        Thread.sleep(1000);
View Full Code Here

                theSocket.isBound());
        theSocket.close();

        // connect causes implicit bind
        theSocket = new DatagramSocket(null);
        theSocket.connect(new InetSocketAddress(addr, port));
        assertTrue("Socket indicated not bound when it should be (3)",
                theSocket.isBound());
        theSocket.close();

        // now test when we bind explicitely
View Full Code Here

        // base test
        DatagramSocket theSocket = new DatagramSocket(ports[1]);
        assertFalse("Socket indicated connected when it should not be",
                theSocket.isConnected());
        theSocket.connect(new InetSocketAddress(addr, port));
        assertTrue("Socket indicated  not connected when it should be",
                theSocket.isConnected());

        // reconnect the socket and make sure we get the right answer
        theSocket.connect(new InetSocketAddress(addr, ports[2]));
View Full Code Here

            throw new DomainProtocolException(Messages.getString("jndi.40")); //$NON-NLS-1$
        }
        try {
            dSocket = new DatagramSocket();
            srvAddr = InetAddress.getByAddress(srvAddrArr);
            dSocket.connect(srvAddr, serverPort);
            outPacket = new DatagramPacket(outBuf, outBufLen, srvAddr,
                    serverPort);
            dSocket.setSoTimeout(timeout);
            dSocket.send(outPacket);
            inPacket = new DatagramPacket(inBuf, inBufLen, srvAddr, serverPort);
View Full Code Here

            byte theBytes[] = { -1, -1, -1, -1 };

            // validate we cannot connect to the broadcast address when
            // setBroadcast is false
            try {
                theSocket.connect(new InetSocketAddress(InetAddress
                        .getByAddress(theBytes), ports[1]));
                assertFalse(
                        "No exception when connecting to broadcast address with setBroadcast(false)",
                        theSocket.getBroadcast());
            } catch (Exception ex) {
View Full Code Here

            }

            // now validate that we can connect to the broadcast address when
            // setBroadcast is true
            theSocket.setBroadcast(true);
            theSocket.connect(new InetSocketAddress(InetAddress
                    .getByAddress(theBytes), ports[2]));
            ensureExceptionThrownIfOptionIsUnsupportedOnOS(SO_BROADCAST);
        } catch (Exception e) {
            handleException(e, SO_BROADCAST);
        }
View Full Code Here

                    .println("Running test_disconnect(DatagramSocketTest) with IPv6GlobalAddressJcl4: "
                            + Support_Configuration.IPv6GlobalAddressJcl4);
            ds = new DatagramSocket();
            inetAddress = InetAddress
                    .getByName(Support_Configuration.IPv6GlobalAddressJcl4);
            ds.connect(inetAddress, 0);
            ds.disconnect();
            assertNull("Incorrect InetAddress", ds.getInetAddress());
            assertEquals("Incorrect Port", -1, ds.getPort());
        }
    }
View Full Code Here

        assertEquals("Expected -1 for remote port as not connected", -1,
                theSocket.getPort());

        // Now connect the socket and validate that we get the right port
        int portNumber = 49152; // any valid port, even if it is unreachable
        theSocket.connect(InetAddress.getLocalHost(), portNumber);
        assertEquals("getPort returned wrong value", portNumber, theSocket
                .getPort());
    }

    /**
 
View Full Code Here

        server = new DatagramServer(serverPortNumber, localHost);
        server.start();
        Thread.sleep(1000);

        ds.connect(new InetSocketAddress(localHost, serverPortNumber));

        byte[] sendBytes = { 'T', 'e', 's', 't', 0 };
        DatagramPacket send = new DatagramPacket(sendBytes, sendBytes.length);
        ds.send(send);
        Thread.sleep(1000);
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.