Maximum Datagram size for UDP Sockets

  • Thread starter Thread starter Gregory Hassett
  • Start date Start date
G

Gregory Hassett

Hello,

Does anyone know how to get the maximum size of a datagram for a UDP Socket
created via .NET's System.Net.Sockets.Socket class?

Thanks!
 
UDP messages are called "datagrams" because they assume each
message will fit within a single packet for delivery. However, defining the
maximum size of a UDP datagram depends on lots of factors.

The length field of the UDP header allows up to 65535 bytes of data.
However, if you are sending your UDP packet across an Ethernet network, the
Ethernet MTU is 1500 bytes, limiting the maximum datagram size. Also, some
routers will attempt to fragment large UDP packets into 512 byte chunks.

So its more than .NET that determines "datagram" maximum size.
 
Gregory Hassett said:
Does anyone know how to get the maximum size of a datagram for a UDP
Socket created via .NET's System.Net.Sockets.Socket class?

A UDP datagram can't be more than 64K because the length is a 16 bit
integer (regardless of language or environment). I can't find .NET
documentation that states that so it might do something under the
covers to make you think it will send bigger datagrams, but I wouldn't
count on it.

Joe
 
Peter Bromberg said:
UDP messages are called "datagrams" because they assume each message
will fit within a single packet for delivery. However, defining the
maximum size of a UDP datagram depends on lots of factors.

The length field of the UDP header allows up to 65535 bytes of data.
However, if you are sending your UDP packet across an Ethernet
network, the Ethernet MTU is 1500 bytes, limiting the maximum
datagram size. Also, some routers will attempt to fragment large UDP
packets into 512 byte chunks.

The MTU doesn't limit the maximum datagram size, the length field in
the IP header does. Fragmentation is performed routinely when the
datagram size exceeds the physical capacity of a network segment. I'm
not sure where the 512 byte chunks come from though, it depends on
what can be sent over the next link.

Joe
 
Gregory Hassett said:
Hello,

Does anyone know how to get the maximum size of a datagram for a UDP
Socket
created via .NET's System.Net.Sockets.Socket class?

Thanks!

The maximum UDP Datagram size is determined by the underlying transport and
the subnet, .NET (or more exactly the Winsock library) has nothing to do
with this. The max. size can never exceed 64Kb, to get the max. size of the
outbound (send) message supported by the local transport provider (note
"local provider" here ! that means that the value returned is not
necessarily the message size that can be used end-to-end), you'll have to
call GetSockopt through PInvoke. Note that there is no way to get the
receive max. message size.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top