Richard Knop
Richard Knop

Reputation: 83745

How to increase a maximum packet size for UDP?

I am usually sending packets that range from 3 to 15 KB but from time to time I need to send a large packet which is about 0.8-0.9 MB. In that case the UDP socket will stop because there is probably some limit on a single packet size.

How can I increase this limit so I can send large packets?

Upvotes: 0

Views: 5401

Answers (3)

user502515
user502515

Reputation: 4454

It is possible to use packets >64K, despite the size limitation of fields in the layer-4 headers. See IPv6 Jumbograms.

Upvotes: 2

James McNellis
James McNellis

Reputation: 355267

The length field in the UDP packet header is only 16 bits in width; you can't have a single UDP packet larger than 65,535 bytes (that includes the header, too, so really the limit is 65,527 bytes; it's probably even lower still since IP has other restrictions).

Upvotes: 5

Javier
Javier

Reputation: 62631

note that UDP packets bigger than the MTU's (at every hope between your hosts) will be split by IP. If a single one of these parts is lost, the whole UDP packet will be discarded. There's no retransmission.

On a local LAN, with low traffic you might not note the difference, but in any not-so-ideal situation, it could be a huge performance hit.

I think it would be much better to either:

  • use TCP for anything bigger than a few KB's
  • split your messages (you'll find pretty soon you're reinventing TCP)
  • use some other well-tested protocol on top of UDP. One example is UDT

Upvotes: 4

Related Questions