Code example for DatagramPacket

Methods: getData, getLength, getOffset

0
    } 
 
    public int read() throws IOException { 
        if (data == null) {
            socket.receive(packet);
            byte[] packetData = packet.getData();
            data = ByteBuffer.wrap(packetData, packet.getOffset(), packet.getLength());
        } 
 
        if (data.position() >= data.limit()) {
            data = null;
            return read(); 
        } else { 
            return data.get();
        } 
    } 
}