First, network tiering
Computers on the network can communicate with each other because they abide by the mutual understanding of the Internet Protocol (as people communicate, two people can communicate, each other must know the language of the object), the Internet computer communication and root in the network between the middle and the layer of communication, The OSI model divides network communication into seven layers: physical layer, Data link layer, network layer, transport layer, Session layer, presentation layer, and application layer, which is easy to understand for the development of network application staff, which generally divides the network into five layers. These five layers are: physical layer, Data link layer, network layer, Transport layer and application layer (top level), below is a network layered picture (from the network):
Ii. agreements at each level
The communication between the computers in the network is to achieve the communication between layer and layer, to achieve the communication between layer and layer, then each layer must obey the rules, so as to complete better communication, we will make the rules that abide by them are called "agreement", however, the protocols of the five layers on the network are different, each layer has its own protocol. Here's a bottom-up story of each layer of protocol.
2.1 Physical Layer Protocol
The physical layer is the lowest level in the five-tier model, and the physical layer provides the transmission media and interconnection equipment for data communication between computers, providing a reliable environment for data transmission, including cable, optical fiber, wireless channel and so on, interconnection device refers to the interconnection device between computer and modem, such as various plugs and sockets. The role of this layer is to transparently transmit a bit stream (i.e., a binary stream), providing a physical connection to the data link layer that transmits the original bit stream.
2.2 Data Link Layer
Data Link layer is the 2nd layer in the model, the layer docking by the physical layer transmitted by the bit Stream grouping, a group of electrical signals composed of packets, called "frame", the data link layer is to transfer the "frame" unit of the packet, the data to the previous layer (network layer), Frame data consists of two parts: frame head and frame data , the frame header includes the Physical address of the receiver (that is, the address of the network card ) and other network information, and the frame data is the data body to be transmitted. The maximum data frame is 1500 bytes , and if the data is long, it must be split into multiple frames for sending.
2.3 Network Layer
This layer establishes a connection between two nodes through addressing (addressing address), and we all know that our computer is connected to a network with an IP address, and we can use IP addresses to determine whether different computers are on the same subnet. If our computer is connected to the network after two kinds of address: Physical Address and network address (IP address), the network of computers to communicate, you must know the communication of the computer "where", first through the network address to determine whether the same sub-network, The Physical Address (MAC) address is then processed to determine exactly where the computer is to be communicated.
In the network layer has our familiar IP protocol (that is, the protocol that specifies the network address), is now widely used in the fourth edition of IP Protocol (IPV4), this version, the network address is composed of 32-bit bits. We can configure their own IP address can also be automatically obtained by the IP address, the IP address is divided into two parts, the first 24 bits for the network, the last 8 to represent the host number , such as 192.168.254.1 and 192.168.254.2 are in the same subnet because the first 24 bits of the two IP addresses are the same.
The network layer transmits the data in the form of an IP packet, and the IP packet includes two parts: header (head) and data, and the IP packet is placed in the data portion of the data frame for transmission.
2.4 Transport Layer
With Mac and IP address, we can find any two hosts on the Internet to establish communication. However, there is a problem, to find the host, there are many programs on the host need to use the network, for example, you listen to songs and friends QQ chat, when sent to a packet on the network, how to know that it is the content of the chat or the content of the song, At this time, we need a parameter to indicate which program (process) This packet is sent to use, this parameter is called the port number , the host uses the port number to identify the different program (process), the port is an integer between 0 and 65535. Ports 0 to 1023 are system-occupied, and users can only select ports greater than 1023.
the function of the transport layer is to establish port-to-port communication, the network layer is to establish the host and host communication , so that if we determine the host and port, so that the communication between the program can be achieved. What we call socket programming is the communication between the transport layers through code . The IP address and port number are specified because the socket class object is initialized.
There are two very important protocols in the Transport layer: UDP Protocol and TCP protocol
With the UDP protocol, the transmission is UDP packet, the same UDP packet is also header and data two parts, the head part mainly identifies the send port and the receiving port , the data part is the specific content information. The same UDP packet is placed in the "data" portion of the IP packet, and the IP packet is then placed in the data frame for transmission over the network.
Because of the poor reliability of the UDP protocol (unable to determine whether or not the other party received it after the data is sent), a high-reliability protocol--TCP protocol is defined, and the TCP protocol takes a handshake to ensure that the other party receives the data.
2.5 Application Layer
The application layer is the topmost layer in the model, which is the interface between the user and the network, which accomplishes the application requirements of the network users through the application. This layer of data is placed in the data portion of the TCP packet, which defines a very important protocol--http protocol, our general Web development is based on the application layer of development, so the following topics will introduce you to the HTTP protocol. Understanding the HTTP protocol can help us understand the request-response model of ASP and help us customize the issuing of requests and custom servers.
Iii. Summary
Now, a simple example of accessing the Web page illustrates the communication in the network.
When we enter www.baidu.com in the browser, this means that the browser to send a Web page packet to Baidu, to send packets, need to know the other side of the IP address, here we only know the URL is www.baidu.com, but do not know the IP address, at this time The Application Layer Protocol DNS Protocol resolves the URL to an IP address, and a DNS packet is sent to the DNS server. The DNS server responds again to tell us that Baidu's IP address is 220.181.111.147, so we know the IP address of Baidu (the host we need to communicate with).
Application layer:
The Web page is based on the HTTP protocol, and the HTTP packet is embedded in the TCP packet, at which point we send the contents of the HTTP packet:
GET http://www.baidu.com/HTTP/1.1Accept:application/x-ms-application, Image/jpeg, Application/xaml+xml, Image/gif, Image/pjpeg, APPLICATION/X-MS-XBAP, Application/vnd.ms-excel, Application/vnd.ms-powerpoint, Application/msword, * * *accept-language:en-ususer-agent:mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; trident/5.0; SLCC2;. NET CLR 2.0.50727;. NET CLR 3.5.30729;. NET CLR 3.0.30729; Media Center PC 6.0;. net4.0c;. net4.0e; Zune 4.7; infopath.3; MS-RTC LM 8) Accept-encoding:gzip, deflate, peerdistproxy-connection:keep-alivehost:www.baidu.comcookie:bdsfrcvid= h1k_jgc2l434o0a3slyrhiydwflxpm7c3j; h_bdclckid_sf=tjat_c8htdv5hturj63d5jch-unlqmkdwaoz0h8-ai-5mbax-jb6hhfxm-r80nblbtbt2c3nthf0hponhj8bej5l3j; baiduid=c0e879d1a40237e70e9fa559d40ee0ac:fg=1; bdut=w5n3c0e879d1a40237e70e9fa559d40ee0ac13914a661370; bduss= Feqvdndjllmtyyylrxy3zzbw1hm2htemdqzfvjcwrlwmfbaetqd1fotdnxee5squfbqufbjcqaaaaaaaaaaaoqyysaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa Aaaaaaaaaaaaaaaaaaaaaaaaaadewlji2lje5ny43nwaAAADAXFINAAAAAPCNJLD3DSZQYV; Bdrcvfr[eyjbpwsqvss]=2g3v5sbi-ncpv4eilpoxi4wuvy; hm_lvt_9f14aaa038bbba8b12ec2a4a3e51d254=1344671219756; hm_lpvt_9f14aaa038bbba8b12ec2a4a3e51d254=1344671219756x-p2p-peerdist:version=1.0
Transport Layer:
TCP packet needs to set the port, the receiver (Baidu) HTTP port default is 80, the local port is a random integer between 1024-65535, this is assumed to be 1025, so that TCP packets by the header (identifying the sender and receiver of the port information) +http packets, Such TCP packets are then embedded in the IP packets to be transmitted over the network.
Network layer:
IP packets need to know the IP address of both sides, the native IP address is assumed to be 192.168.1.5, the recipient IP address is 220.181.111.147 (Baidu), so that the IP packets are +TCP packets by the header (IP address information).
Data Link Layer:
The IP packet is embedded in the data frame (Ethernet packet), the Ethernet packet needs to know both sides of the Mac (physical address), the sender is the local network card address, the receiver is the gateway 192.168.1.1 MAC address (through the ARP Address Resolution Protocol obtained). This makes the data frame consist of a header (MAC address) +IP packet.
After the forwarding of multiple gateways to the Baidu server 220.181.111.147, the server accepts the Ethernet packet sent over, then extracts the IP packet-->tcp packet-->http packet from the Ethernet packet, and finally the server makes an "HTTP response", Then the TCP protocol is sent back to the client (browser), the same process of the browser reads the content of the HTTP response (HTTP response packet), and then the browser docking by the HTML page to parse, the page is displayed to the user, so that the completion of a network communication.
Transferred from: http://www.cnblogs.com/zhili/archive/2012/08/11/NetWorkProgramming.html
Topic One: Introduction to Network Protocols