
378 12. Network Programming
if(mode == CLIENT && type == UNCONNECTED_TCP)
{
ret = connect(sock,(SOCKADDR*)(&remoteAddr),sizeof(remoteAddr));
if (ret == SOCKET_ERROR) {
status = WSAGetLastError();
if (status == WSAEISCONN) // If connected
{
ret = 0; // Clear SOCKET_ERROR
type = CONNECTED_TCP;
}
else
{
if ( status == WSAEWOULDBLOCK || status == WSAEALREADY)
return NET_OK; // No connection yet
else
return ((status << 16) + NET_ERROR);
}
}
}
Listing 12.5(b). e connect function is called for unconnected TCP clients.
12.7.2 Winsock sendto Function
e Winsock sendto function sends the data to the destination. e function syntax is:
int sendto(
SOCKET ...