Code example for DatagramPacket

Methods: getData, getLength, getOffset

0
        this.dp = packet;
        Server = udpf;
    } 
 
    public void handlePacket(DatagramSocket ds, DatagramPacket dp) {
        byte[] buffer = dp.getData();
        int offset = dp.getOffset();
        int length = dp.getLength();
        int a = 0;
        try { 
            byte[] buf = new byte[16];
            System.arraycopy(buffer, 0, buf, 0, buf.length);
            String mid = new String(buf, "US-ASCII");
            System.out.println(mid);
            Server.setMID(mid);
            this.mediator.collegueChanged("GETPACKET");
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(ConnectionHandler.class.getName()).log(Level.SEVERE, null, ex);
        } 
    }