Code example for DatagramSocket

Methods: connectgetPort

     * @tests 
    public void test_getPort() throws IOException { 
        DatagramSocket theSocket = new DatagramSocket();
        assertEquals("Expected -1 for remote port as not connected", -1,
        // 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
    public void test_getReceiveBufferSize() throws Exception { 
        DatagramSocket ds = new DatagramSocket();
        assertTrue("Incorrect buffer size", ds.getReceiveBufferSize() >= 130);