Beej's Guide Network to Programming series serialization 19

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.