|
connect |
Top Previous Next |
|
The connect function establishes a connection to a specified socket.
Syntax
The meaning of the connect function differs depending on the type of socket specified by the argument socket. If socket belongs to a connection-oriented protocol (TCP), connect attempts to establish a connection to the address specified by the address argument. If socket belongs to a connection-less protocol (UDP), the socket's peer address is set but no connection is made. For SOCK_DGRAM sockets, the peer address identifies where all datagrams are sent by subsequent send function calls, and limits the remote senders for subsequent recv function calls.
Parameters socket A descriptor identifying an unconnected socket.
serverAddr A pointer to the sockaddr structure to which the connection should be established.
addrLen The length, in bytes, of the sockaddr structure pointed to by the serverAddr argument.
Return value If no error occurs, connect returns 0 otherwise it returns -1. If an error occurs errno indicates the error. |