liamzebedee
liamzebedee

Reputation: 14490

When creating a Java UDP server, how many bytes do I allocate for the packet buffer?

public DatagramPacket(byte[] buf,int length)
// Constructs a DatagramPacket for receiving packets of length length. 

Using the vanilla Java classes for a UDP server (DatagramSocket), how am I supposed to calculate the buffer size for an incoming packet? I have looked through the javadocs, and there seems to be a method called getReceiveBufferSize(), but I really don't know what I would use the returned data for.

Upvotes: 1

Views: 775

Answers (1)

Martin James
Martin James

Reputation: 24887

Assuming you have no other clue from your app/protocol requirements/spec, 64K is a good size - it will never be too small.

Upvotes: 2

Related Questions