Reputation: 1828
When I call Socket.ReceiveFrom
I get the following exception:
System.Net.Sockets.SocketException: A message sent on a datagram socket was larger than the internal message buffer or some other network limit, or the buffer used to receive a datagram into was smaller than the datagram itself.
However, I have only sent a packet with 118 bytes.
The code is quite simple:
numBytesRead = udpSocket.ReceiveFrom(data, ref _udpRemoteEndPoint);
Where data is allocated to 1200 bytes.
What am I doing wrong?
It's worth mentioning that I get this error only when running on Windows - the code works well on my Mac.
A few more details: I am writing in C# code in Unity (game engine).
I have one TCP
socket and one UDP
socket open on each machine. I am using a Select
loop to handle both in the same thread, so I call ReceiveFrom
only after I know that data is available. I'm using TcpClient
and UdpClient
to create the sockets.
EDIT: This question is different because I'm not sending big packets. I don't suppose my 118-byte payload should overflow any internal buffer.
Upvotes: 1
Views: 6201
Reputation: 11
You have to set enough space for the buffer: byte[] data = new byte[1024];
Also the call is made this way: udpSocket.EndReceiveFrom(ar, ref _udpRemoteEndPoint); where ar is IAsyscResult type.
Upvotes: 1