0

I'm working on a server-client application based on UDP protocols. The server is written in c++ and the client is in C#.

On the server side I get the buffer using the recvfrom():

int bufLen = recvfrom(s, buf, 1024, NULL, (sockaddr*)&addr, &addrlen);

The weird thing is that the received buf is exactly what I've sent from the client but the bufLen is -1 which is SOCKET_ERROR.

I have no idea what the problem might be. please help. Thanks a million.

user3530012
  • 720
  • 2
  • 20
  • 37

1 Answers1

1

Your datagram is too big, or your buffer is too small.

The datagram is larger than your buffer, so it gets trucated, you get an error return from recvfrom and GetLastError() returns 10040, ('WSAEMSGSIZE').

Martin James
  • 24,453
  • 3
  • 36
  • 60
  • My buffer size is the exact length of the buffer sent from the client. how can I use a bigger datagram? – user3530012 Dec 29 '14 at 12:59
  • Hmm.. are you sure? Check again, and double the buffer to 2048 to see what happens. – Martin James Dec 29 '14 at 13:08
  • I doubled the buffer to 2048 as you said and saw the received buffer length was larger than what I expected. I think I have to look for the problem somewhere else. thanks anyway. – user3530012 Dec 29 '14 at 13:15