BSD Sockets Interface Programmer's Guide

Chapter 2 41
Using Internet Stream Sockets
Writing the Client Process
Requesting a Connection
Once the server process is listening for connection requests, the client
process can request a connection with the connect call. connect and its
parameters are described in the following table.
Include files: #include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
System call: connect(s, addr, addrlen)
int s;
struct sockaddr *addr;
int addrlen;
Function result: 0 if connect is successful, –1 if failure occurs.
Example:
struct sockaddr_in peeraddr;
...
connect (s, &peeraddr, sizeof(struct sockaddr_in));
connect initiates a connection and blocks if the connection is not ready,
unless you are using nonblocking I/O. When the connection is ready, the
client process completes its connect call and the server process can
complete its accept call.
Parameter
Description of
Contents
INPUT Value
s socket descriptor of local
socket
socket descriptor of socket
requesting connection
addr pointer to the socket
address
pointer to the socket
address of the socket to
which client wants to
connect
addrlen length of address size of address structure
pointed to by addr