The transport layer protocols TCP / UDP

1、UDP

  UDP is a connectionless protocol that does not require before the formal transfer of data to link the two sides, but the UDP protocol data packets porter , does not ensure the orderly transfer without loss to the peer and UDP protocol with no flow control the algorithm, UDP with more portable for TCP.

  feature:

  • Connectionless-oriented : the transmitting side, the application layer passes data to the transport layer protocol is UDP, UDP only increasing the data to a UDP header identifying the protocol is UDP, and then passed to the network layer; at the receiving end, the network layer data passed to the transport layer, UDP only removing the IP header will be passed to the application layer.
  • Unreliability : unreliable UDP protocol mainly in the following areas:
    • No connection, like hair on the hair
    • What data is received and will not transfer any data to back up, it will not shut correctly to receive new peer
    • No congestion control, data has been sent at a constant speed, even if the network is not good adjustment rate when the network packet loss may result in poor
  • Efficient : UDP header overhead is small, only 8 bytes. The two 16-bit port number [source port (optional) + destination port] + length of the entire packet and check the entire data packet is the IPv4 + (optional) Composition
  • Transmission mode : unicast (one to one), multicast (one to many), broadcasting (many to many)
  • Suitable usage scenarios : real-time requirements of high places, such as broadcast, king of glory, etc.

2、TCP

1) Head

  • Sequence Number: This number ensures messages TCP transport is ordered, by the end of the splicing packet sequence numbers
  • Acknowledgement number: order number represents a data receiving terminal to accept a desired number of the next byte code is also expressed on a number of data has arrived
  • window size: the window size, but also indicates how many bytes of data received, for flow control
  • Identifier:
    • URG = 1: present data indicates the data portion of the packet contains emergency information, is a high priority data segment, urgent pointer is valid at this time
    • ACK = 1: represents the acknowledgment number field is valid, all the packets transmitted after the predetermined packet TCP connection ACK = 1
    • PSH = 1: indicates the receiving end should immediately PUSH data to the application layer, rather than waiting for the buffer area is full before submitting
    • RST = 1: Indicates the current TCP connection serious problems that may require you to re-establish the connection
    • SYN = 1: When 1, ACK = 0 when SYN =, represents the current segment is a connection request packet; when SYN = 1, ACK = 1, indicates that the current segment is a connection request packet agree
    • FIN = 1: This segment is represented by a connection request segment release

2) state machine

Performance RTT: round trip time indicates the peer receives the required data to the transmitting side transmits data

Three-way handshake:

  TCP protocol, initiate a request for the client, the passive server is connected, the connection both sides can send and receive data, TCP is a full-duplex protocol

  • The client sends a connection request to the server, the message including its own data communications segment initial sequence number, sending the request, the client will enter the SYN-SENT state
  • After the server receives the connection request packet, if the agreed connection, an acknowledgment is sent, the reply also contains its own data communications initial sequence number, the transmission state after entering SYN-RECEIVED
  • After the client receives the connection reply consent, also need to send a confirmation message to the server, send after entering ESTABILISED state, the server receives also enter ESTABLISHED state

  The reason TCP three-way handshake required: prevent failure of the connection request is received by the server segment which affects error

Four waving :

  • If the client that sends data A is completed, then he needs to send a connection release request server B
  • B, after receipt of the release request, tells the application layer to release the TCP connection, and then sends an ACK packet, and into the CLOSE-WAIT state, A to B represents the connection has been released, no longer receives the data A sent, but the TCP connection is bidirectional, so that B can still send data to a
  • If B is not finished at this time will continue to transmit the transmission data, sends After completion of the connection request to release the A, B and then into the LAST-ACK state
  • A release request is received after sending an acknowledgment to the transponder B, this time into the A TIME-WAIT state, the state will continue 2MSL (maximum segment lifetime) time, if the time period of no retransmission request B will enter CLOSED state. when B receives the acknowledgment also enters the CLOSED state

  A TIME-WAIT state will enter the waiting time 2SML reason: In order to ensure that B can receive the answer A, directly into the CLOSED state if A finished confirm, if confirmation response has not been delivered because of a network problem, it will not cause B normally closed.

 

Guess you like

Origin www.cnblogs.com/qiyangliu/p/11334522.html