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

ParametersDescription
sSocket descriptor returned from a previous call to socket.
namePointer to the sockaddr structure containing the peer address and port number.
namelenLength 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.