The difference between socket communication and tcp communication: 1. The tcp protocol belongs to the transport layer protocol, while socket is an abstraction layer between the application layer and the transport layer; 2. A three-way handshake is required to establish a TCP connection; 3. Socket connections can maintain long connections; 4. TCP server and TCP client use socket communication, etc.
#The operating environment of this article: Windows 10 system, Dell G3 computer.
What is the difference between socket communication and tcp communication?
The difference between tcp and socket
## 1: tcp protocol
The tcp protocol belongs to the transport layer protocol (UDP also belongs to the transport layer protocol, but the UDP protocol is stateless). Establishing a TCP connection requires three handshakes, and disconnecting a TCP connection requires four waves. The mobile phone can use the networking function because the bottom layer of the mobile phone implements the TCP/IP protocol. You can use the mobile phone terminal to establish a TCP connection with the server through the wireless network. The TCP protocol can provide an interface to the upper-layer network, so that the transmission of upper-layer network data is established on an "undifferentiated" network. tcp requires three handshakes to establish a connection: Figure 1: Tcp connection three-way handshake diagram
Figure 2: Four wave waves when the tcp connection is disconnected
2: socket
We know that if two processes need to communicate, the most basic premise is to be able to uniquely identify a process. In local process communication, we can PID is used to uniquely identify a process, but PID is only unique locally. There is a high probability of PID conflict between two processes in the network. At this time, we need to find another way. We know that the IP address of the IP layer can uniquely identify the host, and The TCP layer protocol and port number can uniquely identify a process on the host, so we can use the IP address + protocol + port number to uniquely identify a process on the network. Figure 5: Schematic diagram of the socket communication system module
As you can see from the picture, the socket connection can maintain a long connection.
Figure 6: Basic socket client/server communication process diagram
Note that the socket connection can be actively closed by the client or the server.
For more related knowledge, please visit the FAQ column!
The above is the detailed content of What is the difference between socket communication and tcp communication?. For more information, please follow other related articles on the PHP Chinese website!