TCP connection:
The mobile phone can use the internet function because the mobile phone implements the TCP/IP protocol at the bottom layer, which enables the mobile phone to establish a TCP connection over the wireless network.
To establish a TCP connection, you must go through the "three-way handshake", as shown below:
The first handshake: the client sends a request to the server and waits for confirmation from the server.
The second handshake: the server responds to the client request and sends a response packet to the client.
Third handshake: the client sends a confirmation packet to the server after receiving the response packet from the server.
The package transmitted during the handshake does not contain data. After three handshakes are completed, the client and the server start to transmit data.
Once the TCP connection is established, the TCP connection will remain until either client or server closes the connection.
When you disconnect a TCP connection, both the server and client can initiate a request to disconnect the TCP connection. The disconnection process requires a four-way handshake"
HTTP connection:
HTTP is an application built on TCP. Different from TCP connections, a client requires a server for each request.
Returns a response. After the request ends, the connection is released. Because each HTTP request releases a connection, because the HTTP connection is a "short connection ",
To keep the client online, you must continuously initiate connection requests to the server. Therefore, in the development process, even if you do not need to obtain any data,
The client must also send a request to the server at intervals to ensure normal communication.
Socket connection:
Socket is the cornerstone of communication and the basic operation unit for network communication that supports TCP/IP protocol.
To establish a socket connection, you need a pair of sockets. One of the clients is running, the other is running, and the connection process between sockets is divided
Three steps: server listening, client request, and connection confirmation.