Code example for DatagramPacket

Methods: getData, getLength, getOffset

0
 
    /** 
     * @tests java.net.DatagramPacket#DatagramPacket(byte[], int, int) 
     */ 
    public void test_Constructor$BII() { 
        DatagramPacket dp = new DatagramPacket("Hello".getBytes(), 2, 3);
        assertEquals("Created incorrect packet", "Hello", new String(dp
                .getData(), 0, dp.getData().length));
        assertEquals("Wrong length", 3, dp.getLength());
        assertEquals("Wrong offset", 2, dp.getOffset());
    } 
 
    /** 
     * @tests java.net.DatagramPacket#DatagramPacket(byte[], int, int, 
     *        java.net.InetAddress, int) 
     */ 
    public void test_Constructor$BIILjava_net_InetAddressI() throws IOException { 
        DatagramPacket dp = new DatagramPacket("Hello".getBytes(), 2, 3,
                InetAddress.getLocalHost(), 0);
        assertEquals("Wrong host", InetAddress.getLocalHost(), dp.getAddress());
        assertEquals("Wrong port", 0, dp.getPort());