In making a connection, the client makes a connection while the server waits for and accepts the connection. Here we discuss what the client program must do, using the connect
function, which is declared in `sys/socket.h'.
connect
function initiates a connection from the socket with file descriptor socket to the socket whose address is specified by the addr and length arguments. (This socket is typically on another machine, and it must be already set up as a server.) See Socket Addresses, for information about how these arguments are interpreted.
Normally, connect
waits until the server responds to the request before it returns. You can set nonblocking mode on the socket socket to make connect
return immediately without waiting for the response. See File Status Flags, for information about nonblocking mode.
The normal return value from connect
is 0
. If an error occurs, connect
returns -1
. The following errno
error conditions are defined for this function:
EBADF
ENOTSOCK
EADDRNOTAVAIL
EAFNOSUPPORT
EISCONN
ETIMEDOUT
ECONNREFUSED
ENETUNREACH
EADDRINUSE
EINPROGRESS
EALREADY