Original Post
========:EDIT SOLVED:========= Okay, for anyone else who gets this problem... The last parameter of recvfrom() is a pointer to the length of the sockaddr struct (2nd to last parameter). While I assumed that this would be filled by function (which it does), it also should be set to the size of your particular sockaddr struct when it is passed in. Can't believe I spent hours on that, heh. Sorry If I'm adding to the noise of this forum. -------------------------------------------------------------------------- Original Post: -------------------------------------------------------------------------- I'm trying to write a simple server/client program to help myself learn Winsock. However I've come across a problem. Here's what happens: I bind my sockaddr_in address to the UDP socket (blocking) that I've created. sockaddr_in looks like: addr.sin_family = AF_INET addr.sin_port = htons(portNum) addr.sin_addr.s_addr = INADDR_ANY; //Also htonl(INADDR_ANY) has been tried Then I start a loop which begins with a call to recvfrom(..). Now the expected behavior is that recvfrom(..) will block until it gets some data. However, what happens is it returns -1, and WSAGetLastError reports WSAEINVAL - which means that my socket is unbound. (BUT I have bound it prior!) The loop keeps spinning instead of being blocked by recvfrom() every loop. Now, on my client I can send a bit of data to the server. And instantly the problem goes away -- It stops looping and actually blocks every time recvfrom(..) is called. So is there some kind of late binding going on here? Why does winsock think my socket is unbound until it first receives data? I wouldn't even have noticed this, had I not printed 'Waiting:' at the start of each loop. Any ideas? Edit: Paste bin of pertinent code