Code example for DatagramPacket

Methods: getAddressgetLengthgetPort

0
 
    private Packet recieve() { 
	Packet p = new Packet();
 
	byte bData[] = new byte[INITIAL_BUFFER_SIZE];
	packet = new DatagramPacket(bData, bData.length);
	try { 
	    socket.setSoTimeout(SOCKET_TIMEOUT);
	} catch (SocketException e) {
	    handleException(e);
	    return null; 
	} 
	try { 
	    socket.receive(packet);
	    String bufferJson = new String(bData, 0, packet.getLength());
	    BufferResponse br = new Gson().fromJson(bufferJson,
		    BufferResponse.class); 
	    bData = new byte[br.buffer];
	    packet = new DatagramPacket(bData, bData.length);
	    socket.receive(packet);
Contextual code suggestions in your IDE  Get Codota for Java