Code example for SocketException

0
    } 
 
    public synchronized void receive(DatagramPacket p) throws IOException {
        log.debug("Emulate receive: " + p);
        if (toRead == null) {
            throw new SocketException();
        } 
 
        p.setData(toRead.getData());
        p.setAddress(toRead.getAddress());
        //p.setSocketAddress(toRead.getSocketAddress()); 
        toRead = null;
    } 
 
    public void send(DatagramPacket p) throws IOException {
        log.debug("Emulate send: " + p);
    } 
 
    public void setDatagramToReceive(DatagramPacket datagramPacket) {
        toRead = datagramPacket;
    }