Socket message sometimes not sent in Windows 7/2008 R2

When sending two UDP messages to a computer in Windows 7, it seems that sometimes the first message is not sent at all. Has anyone else experienced this?

The below test code demonstrates the problem on my machine. When I run the test program and watch all UDP traffic until 10.10.42.22, I see how the second UDP message is sent, but the first UDP message is not sent. If I run the program again, then both UDP messages are sent.

It does not interrupt every time, but this usually happens if I wait a couple of minutes before retesting.

#include <iostream> #include <winsock2.h> int main() { WSADATA wsaData; WSAStartup( MAKEWORD(2,2), &wsaData ); sockaddr_in addr; addr.sin_family = AF_INET; addr.sin_port = htons( 52383 ); addr.sin_addr.s_addr = inet_addr( "10.10.42.22" ); SOCKET s = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ); if ( sendto( s, "TEST1", 5, 0, (SOCKADDR *) &addr, sizeof( addr ) ) != 5 ) std::cout << "first message not sent" << std::endl; if ( sendto( s, "TEST2", 5, 0, (SOCKADDR *) &addr, sizeof( addr ) ) != 5 ) std::cout << "second message not sent" << std::endl; closesocket( s ); WSACleanup(); return 0; } 
+4
source share
1 answer

The problem here is basically the same as this post , and this is related to section 2.3.2.2 of RFC 1122:

2.3.2.2 ARP packet queue

The communication layer MUST save (and not refuse) at least one (last) packet of each set of packets destined for the same unresolved IP address and transmit the saved packet when the address has been resolved.

It seems that opening a new socket for each UDP message is a workaround.

+3
source

All Articles