Network Programming (1) -- easy understanding of network resource positioning and Network Programming Network Resources

Source: Internet
Author: User

Network Programming (1) -- easy understanding of network resource positioning and Network Programming Network Resources

It sounds very difficult to learn network programming at the beginning. At that time, if you followed the correct method and understood more, it would be easy to learn network programming. In this process, we need to keep providing examples and code. Let's take a look. I believe it will be very rewarding if you stick to learning network programming knowledge. If you have never been familiar with the basic knowledge of computer networks, I recommend a textbook "computer network version 6". This book is very good and will be helpful for beginners who are familiar with computer networks.

The following are some basic concepts: clients: widely speaking, they are application programs used by customers. In daily use, mobile phone software QQ, and Dialers are clients. Server: The image point is the Cheng Xun application that processes the requests sent from the client application. Internet: TCP/IP protocol groups are used as communication rules. In daily life, what we call "Internet" and "Internet access" must be directly or indirectly connected to the Internet. Why is it direct or indirect? A network is a nested model (Internet) that involves complex concepts such as subnet, lan, and routing. If you are interested, you can learn more. A network is a virtual abstraction concept. In daily life, we are no stranger. Learning Network programming is not only about accessing the internet like a Chinese netizen, but also about how it works and how it can be flexibly programmed. For example:

1) I click to open the Firefox browser (Baidu is my homepage) and view it through  Network Monitoring.





This step is to establish a connection between the client and the server. Generally, you only need to click the hyperlink (the shortcut of a browser) to start HTTP. We can see that the Protocol is TCP. The HTTP protocol we described is based on the TCP protocol in this operation. The second three red boxes are the local IP address and port (client), and the fourth Five empty boxes are the Firefox Server IP address and port (server ). 2) The client establishes a link to send the request. In fact, when we clicked the browser to start working, our computer sent a request to the server. (View request information with Firefox plug-in Firebug)


3) server response link: click on each GET request separately. A response header is displayed. That is, the response from the server.


4) after the client processes each response message, the content is displayed on the user interface and disconnected.



The aforementioned Browser "Baidu event" actually contains many request and response processes. The first thing we learn about network programming is to figure out how each request and response is generated and interacted. The Internet mentioned just now is a "nested" Network (network ). This is similar to the data structure tree. Each tree may have a parent node and a child node.

For example, if I connect to my route through wifi, I can understand that the first gateway I need to pass is my route. The routes in my house and the routes in the next house are connected to a larger router near my house. Layer by layer. In each layer, each host (which may be a computer or mobile phone, but in fact the client is a program of the corresponding device) uses an ID on the network, which is represented by an IP address. The applications on the corresponding host use the "Port. In this way, each device connected to the Internet has a unique IP address and many ports ).

You can search for the.txt file under the C root directory, for example, the C: \ A.txt command in drive C, so that you can directly open the file resource. If we connect to other user devices over the Internet, can we request to open resources on other user devices in a similar way? The answer is yes, provided that the permission of other computers is allowed.


In programming, the "Uniform Resource Locator URL" is used to mark the location of resources obtained on the Internet.

The URL is generally in the case-insensitive format)

<Protocol>: //

<Protocol> include ftp (we should have seen it during downloads by thunder)-File Transfer Protocol FTP; http-Hypertext Transfer protocol HTTP; News-USENET News

<Host> refers to the domain name of the host that stores resources on the Internet. The domain name is also the unique identifier of the host, which is more user-friendly for users.

When I use the "tracert" route tracing command to track "www.baidu.com", the following information is displayed:


If I access the 180.97.33.108 browser, I can also access the Baidu page.



At this time, the role of the domain name is reflected. We track "www.baidu.com" in different regions and get the same route (also a server. The reason is that the Internet is a network-based model, and Baidu's servers are distributed across many parts of the country. When we need to access Baidu, it is directly or indirectly connected to the server currently tracked. If the IP address is used as the host flag, the user needs to input the IP address of the nearby Baidu server in a different place each time. This is unrealistic. Therefore, the domain name is used to "represent the requested host address" in a unified manner, and the Implementation behind it is transparent to users.

<Port>/<path> indicates the file path in a specific program on the host (which can be omitted)

This is relatively simple. If a host is compared to a house, the IP address is the address, and the port can be understood as the room in the house. The port number is the room number. If you want to find a sweater that is placed in the closet with the room number 60, you can use the address + ": 60/wardrobe/sweater.

In this way, we can easily find resources on the network.

For more information, see network programming serialization.






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.