UDPClient message size limit

  • Thread starter Thread starter goa
  • Start date Start date
G

goa

Hi all,

I'm trying to implement basic broadcasting functionality via UDP.

Its all working except for the fact that if the message is over 1472
bytes it does not seem to be received by the client app... and theres
no exceptions being raised (by either the server or client).

I've read a number of posts indicating that you should be able to send
messages of over 50,000 bytes, and no one has seem to have struck the
same problem. I'm new to UDP so am I just missing something simple?

I'm determining the 1472 bytes just from the byte array i'm passing in.

The code is basically as below (but i've stripped out all the
threading, etc):

Server:
public class UDPBroadcaster
{
private IPEndPoint ipEP = null;
private UdpClient server = null;

public void Send(string message)
{
byte[] data = System.Text.Encoding.ASCII.GetBytes(message);
this.server.Send(data, data.Length, this.ipEP);
}
}

Client:
public void Receive()
{

IPEndPoint ipEP = new IPEndPoint(IPAddress.Any, this.port);

byte[] data = client.Receive(ref ipEP);
stringData = System.Text.Encoding.ASCII.GetString(data, 0,
data.Length);
}

Thanks,
George.
 
The 1472 bytes is the data bytes an Ethernet packet can carry. From my C++
days (and I don't know if it differs in the DOTNET classes), I had to break
larger messages into packets and send each packet individually. Actually,
using the Socket class and calling SendTo, which was sort of what we had in
C++, should throw an exception if you attempted to send a datagram packet
larger than the max packet size.
There are a few catches using UDP. You may loose packets, thus receiving
packet 2, while packet 1 went missing, and you may receive them out of
sequence, thus 2, 1, 3 for example.
Depending on how reliable you want the scheme to be, it can become quite
complex. The sender must send the message packet count and sequence number
with each packet, and the receiver must assemble the message and take
appropriate actions on lost or out of sequence packets, timeout in case the
last packet got lost, etc.
 
Back
Top