Do I have to bind a UDP socket in my client program to receive data? (I always get WSAEINVAL)

With UDP, you have to bind() the socket in the client because UDP is connectionless, so there is no other way for the stack to know which program to deliver datagrams to for a particular port.

If you could recvfrom() without bind(), you’d essentially be asking the stack to give your program all UDP datagrams sent to that computer. Since the stack delivers datagrams to only one program, this would break DNS, Windows’ Network Neighborhood, network time sync….

You may have read somewhere on the net that binding in a client is lame, but that advice only applies to TCP connections.

Leave a Comment

tech