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; }
source share