When I learned the basics of the university network, the network is divided from bottom to bottom into the physical layer, data link layer, network layer, transmission layer, Session Layer, presentation layer and application layer. Through preliminary understanding, I know that the IP protocol corresponds to the network layer, and the TCP protocol corresponds to the transmission layer, while the HTTP protocol corresponds to the application layer. In essence, the three are not comparable, socket is the encapsulation and Application of TCP/IP protocol (programmer level ). It can also be said that the TPC/IP protocol is the transport layer protocol, mainly to solve how data is transmitted over the network, while HTTP is the application layer protocol, mainly to solve how to package data. The relationship between TCP/IP and HTTP is easy to understand:
"When transmitting data, we can only use the (Transport Layer) TCP/IP protocol. However, without the application layer, we cannot identify the data content, to make the transmitted data meaningful, you must use the application layer protocol. There are many application layer protocols, such as HTTP, FTP, and telnet. You can also define the application layer protocol by yourself. The Web uses HTTP as the application layer protocol to encapsulate HTTP text information, and then uses TCP/IP as the transport layer protocol to send it to the network ."
What is the most commonly used socket? In fact, socket is the encapsulation of the TCP/IP protocol. socket itself is not a protocol, but an interface (API) called through socket, we can use the TCP/IP protocol. In fact, the socket and TCP/IP protocols are not necessarily related. The socket programming interface is designed to adapt to other network protocols. Therefore, the appearance of socket only makes it easier for programmers to use the TCP/IP protocol stack. It is an abstraction of the TCP/IP protocol, this forms some of the most basic function interfaces we know, such as create, listen, connect, accept, send, read, and write. The network has a saying that the relationship between socket and TCP/IP is easier to understand:
"TCP/IP is just a protocol stack. Just like the operating mechanism of the operating system, it must be implemented in detail and provide external operation interfaces. Just as the operating system provides standard programming interfaces, such as Win32 programming interfaces, TCP/IP also provides interfaces that programmers can use for network development. This is the socket programming interface."
I can't think of TCP/IP protocol too much. I just need to check the number of documents about this type of information and books on the Internet, I plan to purchase some classic books (for example, "TCP/IP details: Volume 1, Volume 2, and volume 3") for learning, today, I will summarize some knowledge about TCP/IP-based applications and programming interfaces, that is, a lot of HTTP and socket.
Csdn has a more vivid description: HTTP is a car that provides a specific form of encapsulation or display data; socket is an engine that provides network communication capabilities.
In fact, the TCP at the transport layer is based on the IP protocol at the network layer, while the HTTP protocol at the application layer is based on the TCP protocol at the transport layer, and the socket itself is not a protocol, as mentioned above, it only provides an interface for TCP or UDP programming.
The following are some important concepts that we often encounter during the written examination or interview. Here we will extract and summarize them.
What is the difference between TCP/IP, HTTP, and socket-summer in pink-sunshine one. What is the three-way handshake of a TCP connection?
The first handshake: the client sends the SYN Packet (SYN = J) to the server and enters the syn_send status, waiting for confirmation from the server;
The second handshake: when the server receives the SYN packet, it must confirm the customer's Syn (ACK = J + 1) and send a SYN Packet (SYN = K), that is, the SYN + ACK packet, the server enters the syn_recv status;
The third handshake: the client receives the server's SYN + ACK package and sends the ACK (ACK = k + 1) Confirmation package to the server. After the package is sent, the client and server enter the established status, complete three handshakes.
The package transmitted during the handshake does not contain data. After the three-way handshake is completed, the client and the server formally start to transmit data. Ideally, once a TCP connection is established, the TCP connection will remain until either of the two parties closes the connection. When a TCP connection is disconnected, both the server and client can initiate a request to disconnect the TCP connection. The disconnection process must go through the "Four handshakes" (the process is not detailed, that is, the server interacts with the client, final confirmation of disconnection)
What is the difference between TCP/IP, HTTP, and socket-summer in pink-Sunshine 2. Procedure for establishing a network connection using Socket
To establish a socket connection, you must have at least one socket. One of them runs on the client, which is called clientsocket, And the other runs on the server, which is called serversocket.
The connection process between sockets is divided into three steps: server listening, client requests, and connection confirmation.
1. Server listening: the server socket does not locate the specific client socket, but is waiting for connection. It monitors the network in real time and waits for client connection requests.
2. Client request: the client socket initiates a connection request, and the target is the server socket. Therefore, the client socket must first describe the socket of the server to be connected, point out the address and port number of the socket on the server, and then submit a connection request to the socket on the server.
3. Connection Confirmation: when the server socket monitors or receives a connection request from the client socket, it responds to the request from the client socket and creates a new thread, send the description of the server socket to the client. Once the client confirms the description, both parties establish a connection. The server socket continues to be in the listening status, and continues to receive connection requests from other client sockets.
What is the difference between TCP/IP, HTTP, and socket-summer in pink-Sunshine 3. HTTP link features
The HTTP protocol, Hypertext Transfer Protocol, is the foundation of Web networking and one of the commonly used protocols for mobile phone networking. HTTP is an application built on the TCP protocol.
The most notable characteristic of HTTP connection is that each request sent by the client requires a server to send a response. After the request ends, the connection is released. The process from establishing a connection to closing a connection is called "One connection ".
What is the difference between TCP/IP, HTTP, and socket-summer in pink-Sunshine 4. The difference between TCP and UDP .. I think it's getting worse --\\)
1. TCP is link-oriented. Although network instability and instability determine the number of handshakes, the connection reliability cannot be guaranteed, however, TCP's three-way handshake ensures the connection reliability to a minimum (which is actually guaranteed to a great extent), while UDP is not connection-oriented, before UDP transmits data, it does not establish a connection with the other party, nor does it send a confirmation signal for the received data. The sender does not know whether the data will be correctly received, and of course no re-transmission is required, therefore, UDP is a connectionless and unreliable data transmission protocol.
2. It is also because of the characteristics described in 1 that the UDP overhead is smaller and the data transmission rate is higher, because it does not need to confirm the sending and receiving data, so UDP has a better real-time performance.
Knowing the difference between TCP and UDP makes it hard to understand why MSN using TCP transmission protocol is slower than QQ using UDP, but it cannot be said that QQ communication is insecure, because programmers can manually send and receive UDP data for verification, such as the sender serial number of each data packet and then the Receiver performs verification. Even so, due to the absence of TCP-like "three-way handshakes" in the encapsulation of the underlying protocol, UDP achieves the transmission efficiency that cannot be achieved by TCP.
Reprinted from http://hi.baidu.com/jlhaoran/blog/item/20091a21ba83a74b9922ed59.html