1.2.1.2.13 connect Function

C

int connect(
    SOCKET s, 
    struct sockaddr* name, 
    int namelen
);

Description

The connect function assigns the address of the peer communications endpoint. For stream sockets, connection is established between the endpoints. For datagram sockets, an address filter is established between the endpoints until changed with another connect() function.

Preconditions

The socket function should be called.

Parameters

|Parameters |Description | |s |Socket descriptor returned from a previous call to socket. | |name |Pointer to the sockaddr structure containing the peer address and port number. | |namelen |Length of the sockaddr structure. |

Returns

  • 0 - The function was successful.

  • SOCKET_ERROR (-1) - Function failed. errno is set accordingly. For stream based socket, if the connection is not established yet, errno = EINPROGRESS.

Remarks

None.