RESOLUTION
In the first case, call the bind() function in addition to the socket()
function as shown:
SOCKADDR_IN source_sin;
source_sin.sin_family = AF_INET;
source_sin.sin_addr.s_addr = htonl(INADDR_ANY);
source_sin.sin_port = htons(0);
s = socket(AF_INET, SOCK_DGRAM, 0);
bind(s, (struct sockaddr FAR *)&source_sin,sizeof(source_sin));
WSAAsyncSelect(s, hWnd, WSA_WRITE, FD_WRITE);
The window specified by hWnd in WSAAsyncSelect() will now receive the
FD_WRITE notifications properly.
In second case, call socket() and call connect() asynchronously as shown:
SOCKADDR_IN dest_sin;
dest_sin.sin_family = AF_INET;
dest_sin.sin_addr.s_addr = htonl(SERV_HOST_ADDR);
dest_sin.sin_port = htons(SERVER_TCP_PORT);
s = socket(AF_INET, SOCK_STREAM, 0);
WSAAsyncSelect(s, hWnd, WSA_WRITE, FD_CONNECT | FD_WRITE);
connect(s, (struct sockaddr FAR *)&dest_sin, sizeof(dest_sin);