About the HTTP protocol and TCP, IP protocol in the end in the network protocol hierarchy.

Source: Internet
Author: User
Tags net time switches

Let's look at what happens when we enter http://www.mycompany.com:8080/mydir/index.htmlin the browser, behind the scenes.

First HTTP is an application layer of protocol, in this layer of protocol, is just a communication specification, that is, because the two sides to communicate, we have to agree to a specification beforehand.

1. Connection when we enter such a request, first to establish a socket connection, because the socket is established through the IP and port, so there is a DNS parsing process, the www.mycompany.com into IP, If the URL does not contain a port number, the default port number for that protocol is used.

The process of DNS is this: first we know that our local machine in the configuration of the network will be filled with DNS, so that the machine will send this URL to the configured DNS server, if you can find the appropriate URL to return its IP, otherwise the DNS will continue to send the resolution request to the superior DNS, The entire DNS can be considered a tree structure, and the request will be sent to the root until the result is obtained. Now you have the target IP and port number so that we can open the socket connection.

2. Once the request connection is successfully established, the request is sent to the Web server, which is typically a GET or post command (post is used for the pass of the form parameter). The Get command is in the form of a Get path/file name http/1.0 The file name that is accessed, and http/1.0 indicates the HTTP version used by the Web browser. You can now send a GET command:

Get/mydir/index.html http/1.0,

3. The answering Web server receives this request for processing. Search for subdirectories Mydir file index.html from its document space. If the file is found, the Web server transmits the file content to the appropriate Web browser.

In order to inform the browser, the Web server first transmits some HTTP header information and then transmits the specific content (that is, the HTTP body information), the HTTP header information and the HTTP body information separated by a blank line. Common HTTP header information is: ①http 1.0 OK this is the first line of the Web server answer that lists the HTTP version number and the answer code that the server is running.   The code "OK" indicates that the request is complete.   ②mime_version:1.0 it indicates the version of the MIME type. ③content_type: Type This header information is very important, it indicates the MIME type of the HTTP body information.   Such as: Content_type:text/html indicates that the transmitted data is an HTML document. ④content_length: Length value It indicates the length of the HTTP body information (in bytes).

4. Close the connection: When the answer is finished, the Web browser and Web server must be disconnected to ensure that other Web browsers can connect to the Web server.

The following is a detailed analysis of the data packets that roam through the network.

In the network hierarchy, each layer is strictly one-way dependent. A service is an abstract concept that describes the relationships between layers, a set of operations that are provided to the upper layer in the network. The lower layer is the service provider, and the upper layer is the user requesting the service. The representation of a service is a primitive (primitive), such as a system call or library function. A system call is a service primitive provided by the operating system kernel to a network application or a high-level protocol. The n layer in the network always provides a more complete service to the N+1 layer than the n-1 layer, otherwise there is no value for n layer.

The transport layer realizes "end-to-end" communication, introduces the concept of inter-network process communication, and also solves the problems of error control, flow control, data sorting (message sequencing), connection management, etc., and provides different service modes for this purpose. Typically the transport layer's service is provided by means of a system call, in the form of a socket. For the client, to establish a socket connection, you need to call some of the functions socket () bind () connect () and then send the data via Send ().

Now look at the way the packet is traversing the network:

Application Layer

First we can see in the application layer, according to the current requirements and actions, combined with the application layer of the Protocol, we have determined to send the data content, we put this data in a buffer, and then formed the application layer of the message data.

Transport Layer

This data is sent through the transport layer, such as the TCP protocol. So they will be sent to the transport layer processing, where the message is punched in the header of the transmission head, mainly including the port number, as well as TCP's various system information, this information is directly obtained, because the interface needs to specify the port. This makes up the TCP data Transfer Unit segment. TCP is an end-to-end protocol, the use of such information, such as the TCP header ordinal confirmation sequence number, according to these numbers, the sending party constantly send a wait for confirmation, send a data segment, will open a counter, only after receiving confirmation will send the next, If the excess count time is still not received, the resend is sent, and if the receiving side receives the error data, it is discarded, which causes the send side to time out to resend. Through the TCP protocol, it controls the generation of the sending sequence of packets, continuously adjusts the sending sequence, realizes the flow control and data integrity.

Network layer

Then send the data segment sent to the network layer, in the network layer is packaged, so encapsulated on the network layer of Baotou, Baotou contains the source and destination IP address, the layer of data transmission unit is called Packet. The network layer is responsible for transferring such packets over the network, passing through the router and finally reaching the destination address. Here, depending on the destination IP address, you need to find the address of the next hop route. First on this machine, to find the local routing table, run route print on Windows to see the current routing table contents, as follows: Active Routes Default Route persistent route.

The whole search process is this: (1) According to the destination address, get the destination network number, if in the same intranet, you can send directly. (2) If not, query the routing table to find a route. (3) If no clear route is found, there will also be a default gateway in the routing table, also known as the default gateway, IP with the default gateway address to the next designated router, the gateway may also be a router, or it may only be the network to a specific router to transfer data gateway. (4) After the router receives the data, it routes the remote host or network query again, and if no route is found, the packet is sent to the router's default gateway address. The packet contains a maximum number of hops, and if the hop is exceeded, the packet is discarded, which prevents infinite delivery. After the router receives the packet, it only looks at the packet data of the network layer, the destination IP. So it's working in the network layer, and the data for the transport layer is transparent to it.

If none of the above steps are successful, then the datagram cannot be transmitted. If datagrams that cannot be delivered come from the native, then it is common to return a "host unreachable" or "Network unreachable" error to the application that generated the datagram.

Take the routing table of the host under Windows as an example to see the route lookup process ====================================================================== Active Routes: Network destination            Netmask                       gateway              Interface                   Metric 0.0.0.0                                   0.0.0.0                        192.168.1.2           192.168.1.101            127.0.0.0                               255.0.0.0                    127.0.0.1                127.0.0.1                    1 192.168.1.0                          255.255.255.0            192.168.1.101       192.168.1.101            192.168.1.101                       255.255.255.255       127.0.0.1                127.0.0.1                    10 192.168.1.255                      255.255.255.255       192.168.1.101        192.168.1.101           10  224.0.0.0                             240.0.0.0                    192.168.1.101        192.168.1.101           255.255.255.255                  255.255.255.255        192.168.1.101       192.168.1.101            1 Default gateway:                 192.168.1.2

Network Destination destination segment Netmask subnet mask Gateway IP of the next-hop router entry, the router defines a link to the next router via interface and gateway, typically interface and gateway are in the same network segment. Interface to the destination of the router's export IP (for our personal pc, usually by machine a network card, with the IP address of the network card identification, of course, a PC can also have multiple network cards).

The concept of gateway, mainly for the interaction between the different subnets, when the host, A, a and a two subnets in the network to communicate, first A to send data to its local gateway, and then the gateway then send the data to B's gateway, and then send the gateway to B. Default gateway, when the destination network segment of a packet is not in your routing record, then your router should send that packet to where! The gateway for the default route is determined by the default gateway on your connection, which is the value that we typically configure in the network connection.

Usually interface and gateway are in a subnet, and for routers, because they may have different interface, when a packet arrives, it looks for a matching entry based on the network destination, if found, The interface indicates that the router should be out of that interface, and the gateway represents that subnet's address.

The first article 0.0.0.0 0.0.0.0 192.168.1.2 192.168.1.101 10 0.0.0.0 represents the default route. The route record means: When I receive a packet of the destination network segment is not in my routing record, I will send the packet through the 192.168.1.101 this interface to 192.168.1.2 this address, which is an interface to the next router, so that the packet can be delivered to the next router processing, and I have nothing to do. The route record has a line quality of 10. When multiple entries match, the one with the smaller metric value is selected.

Third 192.168.1.0 255.255.255.0 192.168.1.101 192.168.1.101 10 Direct network segment routing record: What to do when the router receives packets destined for a straight-line segment, in which case the Interfa of the routing record Ce and gateway are the same. When I receive the destination segment of a packet is 192.168.1.0, I will send the packet through 192.168.1.101 this interface directly, because this port directly connected to the 192.168.1.0 this segment, the route recorded by the quality of the line 10 (Because interface and gateway are the same, it means that the packet is routed directly to the destination address and does not need to be forwarded to the router).

In general, the two cases, the destination address and the current router interface is on the same subnet. If it is sent directly, no need to transfer to the router, otherwise it will need to forward to the next router to continue processing.

Once you find the next hop IP address, you also need to know its MAC address, which is loaded into the link layer header as the link layer data. The ARP protocol is required, and the process is to look for ARP buffering, which runs arp-a under Windows to view the current ARP buffer content. If the MAC address of the corresponding IP is included, it will be returned directly. Otherwise, an ARP request is required, which contains the IP and MAC address of the source, the IP address of the destination, and the broadcast within the network, all the main opportunities to check whether their IP is the same as the destination IP in the request, and if it happens, return the MAC address and save the requestor's IP mac. This gets the MAC address of the destination IP.

Link Layer

The MAC address and Link layer control information is added to the packet to form frame, frame under the link layer protocol, complete the data transmission between adjacent nodes, complete the connection establishment, control transmission speed, data integrity.

Physical Layer

The physical line is only responsible for the data being transferred from the host to the next destination in bit units.

After the next destination receives the data, the data is obtained from the physical layer and then goes through the layer-wise unpacking to the link layer to the network layer, then begins the above processing, and then encapsulates the data in the physical layer of the network Layer link layer and continues to pass the following address.

In the above procedure, you can see that there is a routing table query process, and the establishment of this routing table depends on the routing algorithm. That is, the routing algorithm is actually used only to update the maintenance routing table between routers, the real data transfer process does not execute this algorithm, only view the routing table. This concept is also important and requires understanding of commonly used routing algorithms. And the whole TCP protocol is more complex, and the link layer protocol is somewhat similar, there are some important mechanisms or concepts need to be carefully understood, such as number and confirmation, flow control, resend mechanism, send acceptance window.

Basic model and concept of TCP/IP

Physical Layer

Device, repeater (repeater), hub (hub). For this layer, data received from one port is forwarded to all ports.

Link Layer

Protocol: SDLC (Synchronous Data Link Control) HDLC (High-level Data Link Control) PPP protocol independent link device The most common is the NIC, the bridge is also a link product. Some of the functions of the hub modem are considered to belong to the link layer, and there are some controversies that belong to the physical layer device. In addition, all switches need to work at the data link layer, but only the two-layer switch that works on the data link layer. Others like layer three switches, four layer switches, and seven layer switches can work on the three, four, and seven layers of the OSI, but the two-tier feature is still their basic function.

Because of the MAC address table, the conflict is fully avoided because the switch knows which port to forward this data to by the destination MAC address. Instead of being forwarded to all drop ports, like the hub. Therefore, the switch is able to divide the conflict domain drops.

Network layer

Four main protocols: Internet Protocol IP: Responsible for addressing and routing packets between host and network.     Address Resolution Protocol ARP: Obtain the hardware host address in the same physical network.     Internet Control Message Protocol ICMP: sends a message and reports a delivery error about the packet. Interconnect Group Management Protocol IGMP: is taken by the IP host to report host group members to the local multicast router.

The layer device has a three layer switch, router.

Transport Layer

Two important protocols are TCP and UDP.

Port concept: TCP/UDP uses an IP address to identify the web host, using the port number to identify the application process, that is, TCP/UDP uses the host IP address and the port number assigned to the application process to identify the application process. The port number is a 16-bit unsigned integer, and the port number of TCP and the port number of UDP are two separate sequences. Despite the independence of each other, if TCP and UDP provide some well-known service at the same time, two protocols usually choose the same port number. This is purely for ease of use and not for the requirements of the agreement itself. With the port number, multiple processes on one host can use the transport service provided by TCP/UDP at the same time, and the traffic is end-to-end, and its data is passed by IP, regardless of the delivery path of the IP datagram. In network communication, a ternary group can be used globally to uniquely flag an application process: (protocol, local address, local port number).

This means that TCP and UDP can use the same port.

Can be seen through (protocol, source port, source IP, destination port, destination IP) can be used to fully identify a set of network connections.

Application Layer

Based on tcp:telnet FTP SMTP DNS HTTP based on Udp:rip NTP (net TIME Protocol) and DNS (DNS also uses TCP) SNMP TFTP

About the HTTP protocol and TCP, IP protocol in the end in the network protocol hierarchy.

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.