|
connect establishes a connection to a specified socket.
Syntax
int connect( __in SOCKET s, __in const struct sockaddr *name, __in int namelen );
Parameters
s
Socket descriptor for a socket created by socket. If s is connection-oriented, a protocol-specific connection request is targeted to the sockaddr address structure pointed to by name.
name
Pointer to the sockaddr structure to which the connection should be established.
namelen
An integer that defines the length in bytes of the address pointed to by name.
Return Values
0 (zero) if the function succeeds, SOCKET_ERROR if the function fails
Use WSAGetLastError to retrieve a specific error code.
Remarks
For TCP sockets, connect attempts to establish a connection to the specified destination using a 3-way handshake. For sockets with no connections, no data grams are sent. Instead, connect specifies a default destination for subsequent sends on the socket, and restricts the socket to receiving datagrams from the specified remote address. Datagrams can still be addressed to a different destination than the connected socket by using the sendto function.