Code on the client is very similar to the server:
Figure out the address information of the server.
Construct a struct sockaddr_in address.
Get a socket().
connect() to the server.
Use read() and write() to send and receive data.
connect() makes the connection to the server. It returns a file descriptor that you read and write with.
int connect (int socket, const struct sockaddr *address, socklen_t addresslen);
Give it the address to connect to, and it returns zero if the connection succeeds or -1 for an error, with errno set.
Example 14.4 is a client that is a little more convenient than telnet. It follows telnet’s example in searching for the host address: first it does an IPv6 lookup and tries all addresses listed ...