The client requests services from the server by sending a connection request to the socket of the server with the connect() function. On the client side, the connect() call causes a connection to be set up.
In the Internet domain AF_INET, a connection request progresses as follows:
struct sockaddr_in server; ... connect(s, (struct sockaddr *)&server, sizeof server);
In the Internet domain AF_INET6, a connection request progresses as follows:
struct sockaddr_in6 server; ... connect(s, (struct sockaddr *)&server, sizeof server);
The server parameter passes the IPv4 or IPv6 address and the port number of the server with which the client wishes to communicate.
If the socket of the client process has no address assigned at the time of the connect() call, the system selects a name automatically and assigns it to the socket.
If connection setup is unsuccessful, an error code is returned. This can occur, e.g. if the server is not ready to accept a connection (see the next section). However, all names assigned automatically by the system are retained even if the connection setup fails.