Network Programming (1)--Easy to understand network resource location

Source: Internet
Author: User

It sounds hard to start learning network programming. It was easy to learn how to do network programming if you were thinking in the right way and with more understanding. This process requires us to constantly inside and code examples, see the ins and outs, I believe if you insist on reading the Learning Network programming knowledge for everyone will be very fruitful. If have not contacted the basic knowledge of computer network, recommend a textbook "Computer network Sixth Edition", this book speak very good, for the introduction to learn computer network friends will be very helpful.

here are some basic concepts:client: Broadly speaking, it is the application of the client program. The Daily mobile phone software QQ, dialer, and so on is the client. Service side: The image point is the Cheng application that handles the request sent by the client program application. Internet (Internet): TCP/IP protocol groups are used as communication rules. Our so-called "networking" and "Internet" in our daily lives need to be connected directly or indirectly to the Internet. Why is it said here directly or indirectly? Network is a nested model (Internet), involving subnets, LANs, routes and other complex concepts, interested friends can be further understood. A network is a concept of virtual abstraction. We are not unfamiliar in everyday life. Learning Network programming is not just about surfing the internet like Chinese netizens, but also about the principles and principles that can be programmed in a flexible way. To make an analogy:

1) I click to open Firefox (Baidu is my homepage), using 360 network monitoring to view




This step is to establish a connection between the client and the server, usually we just need to click the hyperlink (a shortcut to a browser), and HTTP will begin to work. above we see that the Protocol is the TCP protocol. The HTTP protocol we have described is based on the TCP protocol in this operation. The 23rd red box is the local IP and port (client), and the 45th empty box is the Firefox server IP and port (service side). 2) The client establishes a link to send the request. In fact, when we click on the browser to start working, our computer sends a request to the server. (Use Firefox plugin firebug to view request information)

3) Server Response Link: Open each GET request separately, you can see that there is a response to the header. The response that the server gives.


4) When the client finishes processing each response message, it displays the content in the user's interface and disconnects.


One of the browser "Baidu events" mentioned above actually contains a lot of requests and response processes. And the first thing we learn about network programming is figuring out how each request and response is produced and interacted with. The internet is a "nested" network (network of networks) just mentioned. This is the same as the tree of the data structure. Each tree may have a parent node and child nodes.

For example, I am now using WiFi to connect my home route, can understand I need to pass the first gateway is my home route. And the route to my home and the next home route is a larger router that connects my neighborhood. One layer at a level. Each of the hosts in each tier (which may be a computer/mobile phone, and in fact a program that is the corresponding device for the client) will have an ID, represented by an IP address, in the network. The application on the corresponding host uses "port" to flag. This way, every device connected to the Internet has a unique address (IP), and there are a number of doors (ports).

We usually search the local C packing directory under a "A.txt" file, such as in the C-drive instruction C:\A.txt, so that you can directly open the file resources. So if we and other user devices are connected via the Internet, can we also request to open resources on other user devices in a similar way? The answer is yes, provided that the permission of the other computer is allowed.

Use the Uniform Resource Locator URL in programming to flag the location of resources available on the Internet.

The general form of the URL is (no case sensitivity)

< protocol >://< host >:< port >/< path >

< protocol > contains FTP (usually we should have seen when thunder download)-File Transfer Protocol ftp;http-Hypertext Transfer Protocol Http;news-usenet News

< host > refers to the domain name of the host that holds the resource in the Internet. Domain name is also unique to identify the host, user-friendly use.

Using the "tracert" route tracking command, when I track "www.baidu.com", it shows the following


Try on if I visit 180.97.33.108 in the browser also can visit Baidu page


At this point the role of the domain name is reflected. We use the tracking "www.baidu.com" in different regions to get the same final route (also a server). The reason is that the Internet is a network set of network models, Baidu's server distribution in many parts of the country. When we need to visit Baidu, it is behind the direct or indirect connection to the current tracking server. If you use the IP address as the host flag, then every time users go to a different place, then you need to match the neighboring Baidu server IP into the request, this is not realistic. So the unified use of the domain name to "represent the requested host address", and the implementation behind the user is transparent.

< port >/< path > refers to the path of a file in a specific program on the host (can be omitted)

It's easier here. If a host is compared to a house, then IP is the address, and the port can be understood as the room in the house, the port number is the room number. If I am looking for a sweater that is placed in the closet with the room number 60, you can access it in the form of Address + ": 60/Wardrobe/sweater".

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

For more information, please focus on network programming serial.





Network Programming (1)--Easy to understand network resource location

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.