6. Customer/Server background
This is a world of customers-servers. Everything on the network is dealing with customer processes and server processes. For example, telnet. When you use telnet (customer) to log on to the host through port 23, a program running on the host (usually called telnetd, server) is activated. It processes the connection, displays the login interface, and so on.
Figure 2: Relationship between the client and the server
Figure 2 shows the information exchange between the customer and the server.
Note: the customer-server can use SOCK_STREAM, SOCK_DGRAM, or others (as long as they use the same ). Some good customers -- Server Examples include telnet/telnetd, ftp/ftpd and bootp/bootpd. Each time you use ftp, there is an ftpd at the remote end to serve you.
Generally, there is only one server on the server. It uses fork () to process connections from multiple customers. The basic program is: the server waits for a connection, accepts (accept () connection, and fork () A sub-process processes it. This is what we will discuss in the next section.
6.1. A simple server
All the work done by this server is to send the string "Hello, World! \ N ". If you want to test this program, you can run it on one machine and then log on to another machine:
$ Telnet remotehostname 2349
Remotehostname is the name of the machine where the program runs.
See the specific code: http://www.bkjia.com/kf/201201/116006.html
6.2. A simple client
This program is simpler than the server. All the work of this program is to connect to the host specified in the command line through port 2349, and then get the string sent by the server.
See the specific code: http://www.bkjia.com/kf/201201/116006.html
From the column xiaobin_HLJ80