I am creating a UDP socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP) via Winsock and trying to recvfrom on this socket, but it a
Your other code sample works because you are using sendto before recvfrom. If a UDP socket is unbound and either sendto or connect are called on it, the system will automatically bind it for you and thus the recvfrom call later on will succeed. recvfrom will not bind a socket, as this call expects the socket to have been bound already, or an error will be thrown.