   recvfrom() blocking issue
  while(1){ReceivedData *data = new ReceivedData();std::cout << "Waiting for a datagram\n";int numBytesRecv = recvfrom(m_ServerSocket, (char*)data->GetBuffer(),RECV_NUM_BYTES, 0, (sockaddr*)data->GetClientAddress(),data->GetClientAddressLen());if(numBytesRecv == SOCKET_ERROR){std::cout << "Error " << WSAGetLastError() << " from " << inet_ntoa(data->GetClientAddress()->sin_addr) << "\n";delete data;continue;}EnterCriticalSection(&m_csRecvData);m_ReceivedDataQueue.push_back(data);LeaveCriticalSection(&m_csRecvData);}The problem is I always get error 0 from address 0.0.0.0...when recvfrom should block and wait for something to come...Any ideas why?   
  Are you sure the socket is OK? Is the buffer OK? Is the socket blocking or non-blocking? Is the value at the pointer returned from GetClientAddressLen() actually sizeof(sockaddr_in) when you go into recvfrom?Also, when you receive data, you should assign the output to the "data" packet, because otherwise you don't know how much or how little data was received. If there's a 1-byte packet, for example, and there was a previous packet in the buffer before, then it's quite likely that your logic would assume that you received a copy of the previous packet unless you know how much data was actually received.Finally, when using a queue, you want to also use some primitive to signal that there is data in the queue -- for example, SetEvent() on some event that means that there's data in the queue, so that someone waiting on an empty queue can wake up. Typically, using MsgWaitForSingleObject() or something like that.;  I forgot to put the length of sizeof(sockaddr_in). Still I don't get why does it need the size? It's not like it changes or anything   ;Quote:Original post by Hotshot5000I forgot to put the length of sizeof(sockaddr_in). Still I don't get why does it need the size? It's not like it changes or anythingIt can. For example, when moving from IPv4 to IPv6 the address goes from 32 bits to 128 bits. By accepting the size as a parameter, any future increase in size is catered for using the same API.   