I wrote a c++ windows process (Win7 if it matters) that can send and receive packets using sendto
and recvfrom
, but unfortunately not all of the packets are read from the socket. Both of the computers are directly connected and transmitting bi-directionally 2000 packets (1 packet per second, 500bit each), when I open WireShark I can see that the 2000 packets got to the destination but for some reason my process reads from the socket less than 2000 (~1980 packets). The recvfrom
function is in a task that runs as long as the process is alive.
What could be the reason that the packet gets to the destination but my process didn't receive it? Is there a problem with my code or a known problem with recvfrom or maybe is it because it's udp?
There are no errors involved, this is part of the code:
Update: the problem was with the socket configuration. When i opened it i used setsockopt SO_RCVTIMO of 1 second, changed 1 to 100000 microsecond and it fixed the problem.
socklen_t sockaddr_in_len = sizeof(sockaddr_in);
nResult = recvfrom(s,
buff,
buffLen,
0,
(sockaddr*)sender,
&sockaddr_in_len);
SAFE_UINT ulError = WSAGetLastError();
if (nResult == -1)
{
if(ulError != WSAETIMEDOUT)
{
Sleep(100);
switch (ulError)
{
case WSAECONNRESET:
//Print error
return S_OK;
case WSAEINTR:
//Print error
return S_OK;
case WSAENOTSOCK:
//Print error
return S_OK;
case WSAENOTCONN:
//Print error
return S_OK;
default:
//Print error
return S_OK;
}
}
else
{
//Print error
return S_OK;
}
}
else if (nResult == 0)
{
//Print error
return S_OK;
}