recvfrom on a udp socket does not receive in release build/mode

Category: visual studio vclanguage


Incubbus on Mon, 30 Aug 2010 15:18:14


I wanted to build my client program in release mode and everything seemed to work fine.
The client was able to send data, which have been received by the server.
But the client never receives the answer sent by the server.

1. The server is working correctly
2. The data size is only up to 200 bytes
3. sending works...
4. I am using Visual Studio 2010
5. I am using UDP

Anyone knows why the client cant receive anything in release mode, but in debug mode?

With regards,

following is the code responsible for receiving...


int ret, len, fromlen; //return code / length of the data / sizeof(sockaddr)
   char *buffer; //will hold the data
   char c;
   //recv length of the message
   fromlen = sizeof(sockaddr);
   ret = recvfrom(m_InSock, &c, 1, 0, addr, (addr != NULL) ? &fromlen : NULL);
   if(ret != 1)
   return Inc::ERECV;
   len = (int)c;
   //allocate space for the message
   buffer = new char[len+1];
   //recv message
   fromlen = sizeof(sockaddr);
   ret = recvfrom(m_InSock, buffer, len, 0, addr, (addr) ? &fromlen : NULL);


Fredrick_V on Mon, 30 Aug 2010 18:43:12

I would look at the return value of recvfrom more carefully.  You are looking for 1, which is useful.  I would also look for a return of 0 or SOCKET_ERROR.  0 means the socket was closed.  If you see SOCKET_ERROR, use WSAGetLastError to try to gain further insight into the problem.

Vipin Padinjattayil on Fri, 08 Mar 2019 10:57:32

Go to Project -> Settings -> C/C++ (tab).

Compare the  'Preprocessor definitions', for both Debug and Release builds. All of them should the be same except _DEBUG (for Debug build) and NDEBUG (for Release build).