When learning the tcp udp protocol. We always compare the two to learn from each other. This is because, in some respects, these two protocols always confuse us. In order to clearly define their respective definitions, we must distinguish them. So what are the essential differences between the two? Let's first look at their respective definitions.
TCP: Transmission Control Protocol, that is, the Transmission Control Protocol.
UDP: User Data Protocol, which is the User Datagram Protocol.
TCP is a connection-oriented transmission protocol, that is, a connection must be established before data transmission. UDP is a non-connection-oriented transmission protocol, that is, no connection is required before data transmission.
The two features are compared as follows:
TCP protocol: connection-oriented, high reliability, massive data, and slow Transmission
UDP protocol: for non-connection, low reliability, a small amount of data, fast transmission
We usually use the UDP protocol for QQ, that is, we do not need to establish a connection with the other party when sending data packets. The commonly used ping command belongs to the ICMP protocol, that is, the Internet Control Message ProtocolInternet Control Packet protocol ). It is a sub-Protocol of the TCP/IP protocol family. It is used to transmit control messages between IP hosts and routers. A message control refers to a message of the network itself, such as network connectivity, host accessibility, and routing availability. Although these control messages do not transmit user data, they play an important role in transferring user data.
Tcp udp is a transmission protocol at the IP layer and a processing interface between the IP address and the upper layer. The tcp udp port number is designed to distinguish the IP addresses of multiple applications running on a single device.
Because multiple network applications may run on the same machine, the computer must ensure that the software applications on the target computer that receive data packets from the source host are correct, and the response can be sent to the correct application on the source host. This process is implemented by using the TCP or UDP port number. In the tcp udp header, there are "Source Port" and "Target Port" segments, which are used to display identity identification information during sending and receiving. The combination of IP addresses and port numbers is called "socket ".
Although the service based on the TCP/IP connection protocol stream socket) is the mainstream standard for designing client/server applications, some services can also be provided through the connectionless protocol datagram socket. First, we will introduce the features of TCP socket and UDP socket when transmitting data: Stream (TCP) Socket provides bidirectional, reliable, ordered, and non-repeated data transmission.
Although datax (UDP) Socket provides two-way communication, it is not reliable, ordered, and non-repetitive. Therefore, UDP data transmission may receive unordered and duplicated data, even data is missing during transmission. Because UDP Socket does not guarantee that the data can be completely delivered to the other party during data transmission, most applications use TCP to process the Socket to ensure the correctness of the data. Generally, the send and receive functions of the TCP Socket call the send () and recv () functions, while the UDP Socket uses sendto () and recvfrom () functions () these two functions call the length of the data sent or received. Otherwise, SOCKET_ERROR is returned.