Create sockets, reload the internetwork socket address structure
Create a TCP socket, filling an internetwork socket address structure with the server's IP address and port number
We can get the IP address of the server from the command line parameter
Get the server's well-known port number (Serv_port) from the Unp.h file
Connect to Server
Connect to establish a connection to the server
The STR_CLI function completes the remainder of the client processing work
#include "unp.h" intmain (int argc, char **argv) {intsockfd;struct sockaddr_inservaddr;if (argc! = 2) err_quit ("Usage: TCPCLI <IPaddress> "); sockfd = Socket (af_inet, sock_stream, 0); Bzero (&servaddr, sizeof (SERVADDR)); servaddr.sin_family = Af_inet;servaddr.sin_port = Htons (Serv_port); Inet_pton (Af_inet, argv[1], &servaddr.sin_ addr); Connect (SOCKFD, (SA *) &servaddr, sizeof (SERVADDR)), Str_cli (stdin, SOCKFD);/* Do it All */exit (0);}
TCP Callback Client program: main function