Code example for DatagramSocket

Methods: receive

0
            throw exception;
        } 
    } 
 
    public void test_recv() throws Exception { 
        DatagramSocket s = new DatagramSocket();
        byte[] buf = new byte[200];
        DatagramPacket p = new DatagramPacket(buf, 200);
        new Killer(s).start();
        try { 
            System.err.println("receive...");
            s.receive(p);
            fail("receive returned!");
        } catch (SocketException expected) {
            assertEquals("Socket closed", expected.getMessage());
        } 
    } 
 
    public void test_write() throws Exception { 
        final ServerSocket ss = new ServerSocket(0);
        new Thread(new Runnable() {