Twenty-nine - UDP and TCP

Recently wrote WIFI module, and so want to clear some of the difference between TCP and UDP, before the discovery of understanding or a little misunderstanding. Now re-learning.

 Same point

UDP protocol and TCP protocol is a transport layer protocol

TCP (Transmission Control Protocol, Transmission Control Protocol) is a connection-oriented, reliable byte stream service. Namely the client and server before exchanging data, you must first establish a TCP connection between the two sides, in order to transmit data after. And providing a timeout or retransmission, discarding duplicate data, test data, and other flow control functions, to ensure that data transmitted from one end to another end.

UDP (User Data Protocol, User Datagram Protocol) is a simple datagram-oriented transport layer protocol. It does not provide reliability, just to pass the application layer IP datagram sent out, but can not guarantee that they can reach their destination. Because UDP no longer between the client and server to establish a connection before transmitting data packets, and no timeout retransmission mechanisms, so the transmission is fast.

difference

1, header different

2, different characteristics

3, different protocols

UDP

The maximum length of the UDP datagram 64K (comprising UDP header), if the data length exceeds 64K on the need to manually sub-application layer, UDP packets can not guarantee the order, required number at the application layer.

Feature

1, no connection: Know peer IP and port number on direct transport, without establishing a connection.

2, unreliable: no acknowledgment mechanism, no retransmission mechanisms; if a network fault can not be sent to the other side of the segment, UDP protocol layers application layer will not return any error messages.

3, data reported for: flexible control can not be read and write data and the number of times, the application layer to the UDP packet long, duck UDP transmission, neither split nor combined.

4, the data collection is not flexible enough, but a clear distinction between two data packets, to avoid sticking problems package.

protocol:

NFS: Network File System

TFTP: Trivial File Transfer Protocol

DHCP: Dynamic Host Configuration Protocol

BOOTP: Initiation Protocol (apparatus for diskless boot)

DNS: Domain Name Resolution Protocol

TCP

Features: connection-oriented

1, connection-oriented

TCP three-way handshake

1, contains a host A to host B by sending a data segment sync sequence number flag (SYN) to the host B, B to establish a connection request to the host through the data segment, Host A Host B to tell two things: I want you and communication; the serial number which you can use to respond to me as the starting segment.

2, the host A host B receives the request, and a data segment with the acknowledgment (ACK) and synchronous serial number (SYN) flag in response to Host A, Host A also told two things: I have received your the request, you can transfer the data; the serial number which you want to use as the starting segment to respond to me.

3. After the host A receives the data segment, and then sends an acknowledgment reply confirming the receipt of the data segment host B: "I have received a reply, I now want to start the actual data transmission."

Such 3-way handshake is complete, Host A and Host B can transmit the data.

TCP four waved process

1, when the host A data transfer is complete, the control bit is set to 1 FIN, the TCP connection stop request made.

2, the host B receives the response thereto FIN, the TCP connection acknowledgment will be closed in that direction, the ACK is set.

3, the host A on Host B requests an acknowledgment, ACK is set to 1, both close to the end.

TIME_WAIT state

TCP agreement, a party to take the initiative to close the connection is in the TIME_WAIT state, waiting to get back to the CLOSED state after two MSL (maximum packet lifetime) time.

TIME_WAIT persistence 2MSL, then we can guarantee the segment has not been in both directions of transmission is received late or have disappeared (or restart the server immediately, you may receive the data from late on a process, but this the data is likely to be wrong). But also, in theory, ensure reliable last packet arrives (assuming that the last ACK is lost, then the server will resend a FIN. At this time, although the client process is gone, but still a TCP connection, you can still retransmission LAST_ACK).

 

 

Links: https://blog.csdn.net/sifanchao/article/details/82285018

Guess you like

Origin www.cnblogs.com/smart-zihan/p/11480477.html