Content Summary:
1. Network Seven layer model
2. What is the HTTP protocol
3. What is the socket interface
1. Network Seven layer model
First layer: Physical layer
To provide a reliable environment for the transmission of information between devices, what is this environment?
such as: coaxial cable, plug, receiver, Crystal Head, network cable and so on. A pathway can be formed by connecting devices between the two data terminals of the communication.
Again, one of the provisions of this agreement: for example, Eiars-232-c and rs-449 can be compatible with the 100 sequence line.
Second layer: Data link layer
provide data transfer services. here involves a message is a frame, it is the unit of data transmission, different protocol frame length is different. It also has the function of error recovery, flow control (this refers to the hardware)
iso1745--1975, ISO7776, iso3309--1984 are the three different protocols in this layer, and the length of each protocol frame is different.
Our common link layer products are network cards, bridges and so on.
Layer Three: Network layer
Its function is the choice of routing, activation and termination of the network. It also has an important function is to reuse multiple network connections on a single data link, mostly using time-sharing technology.
We are familiar with routers, gateways, etc.
Layer Fourth: Transport layer
It is the most basic end-to-end level of two computers communicating over the network . Its service satisfies the different needs of transmitting quality, conveying speed and transmitting cost. It also has the function of error recovery, flow control (this refers to software)
Many times we will find the speed of QQ chatting, but we surf the internet is very slow, this is because QQ uses UDP protocol, no error correction function, and the network transmission using the TCP protocol, its error correction function will lead to slow transmission speed.
Level Fifth: Session Layer
Its services enable the application to establish and maintain sessions . Another chestnut: Like two people on the phone, a person said that the other side heard the response to him, this is the session layer in play, it can keep the information in sync, and in order.
Layer Sixth: Presentation layer
It includes the representation of the data, text, graphics, pictures, etc. have their own format, like the format of the picture has jpg,gif and so on.
And the meaning of data is the symbol of the data
The role of this layer is to provide a common language for heterogeneous machine communication in order to interoperate. For example, IBM hosts use EBCDIC encoding, while most PCs use ASCII code. This will be the presentation layer to complete this conversion.
Layer Seventh: Application layer
enables the exchange of information between application processes. There is also a series of service functions required for business processing. Like file transfer, access and management, print services are all part of the application layer.
Simple to understand:
The physical layer, the data link layer, the network layer corresponds to a device, and the device has a certain function on one layer.
The transport layer, the session layer, and the presentation layer correspond to the protocol.
The application layer is what kind of software to use.
2. What is the HTTP protocol
HTTP protocol: Hypertext Transfer Protocol, which corresponds to the application layer, is used to encapsulate the data.
HTTP is a short connection: the client sends a request that requires a server-side loopback response. After the request is over, the link is released actively, so it is a short connection. As a general rule, you do not need any data, and you want to keep a "keep-connected" request to the server at regular intervals. This ensures that the client is "on the Go" state on the server side.
The HTTP connection uses a "request-response" approach, not only to establish a connection on the request, but also to return the data to the server after the client requests it.
3. What is the socket interface
The socket interface is an interface encapsulated with the TCP/UDP protocol.
To understand the Socket, you must understand the TCP connection.
TCP Three-time handshake: The handshake process does not transfer data, after the handshake, the server and the client start transmitting data, ideally, once the TCP connection is established, the TCP connection will persist until either side of the communication is actively disconnected.
Socket is the TCP/IP protocol encapsulation, socket is only an interface is not protocol, through the socket we can use the TCP/IP protocol, in addition to TCP, you can also use the UDP protocol to pass data.
When creating a socket connection, you can specify the transport layer protocol, which can be TCP or UDP, which is a TCP connection and vice versa.
Socket principle
Socket connection, requires at least a pair of sockets, divided into Clientsocket,serversocket connection is divided into 3 steps:
(1) Server monitoring: The server does not locate the specific client socket, but at all times in the listening state;
(2) Client request: The socket of the client to describe the socket of the server it is connecting to, provide the address and port number, and then make a connection request to the server socket;
(3) Connection confirmation: When the server socket receives a request from the client socket, it responds to the client socket request and establishes a new thread that sends a description of the server-side socket to the client. Once the client confirms this description, the connection is formally established. While the server socket continues to be listening, it continues to receive connection requests from other client sockets.
socket is a long connection: Normally the socket connection is a TCP connection, so once the socket connection is established, the communication parties begin to send data content to each other until the two sides are disconnected. In the actual application, because of the network node too much, in the transmission process, will be disconnected by the node, so to poll the high-speed network, the node is active state.
In many cases, it is necessary for the server to actively push the data to the client, to keep the client and the service side of the real-time synchronization.
If both are Socket connections, the server can send data directly to the client.
If the two sides are HTTP connections, the server needs to wait for the client to send the request before the data can be passed back to the client.
Therefore, the client periodically sends a request to the server, not only to remain online, but also to ask the server if there is new data, and if so, pass the data to the client.
"1" HTTP protocol and socket interface differences