In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Foreword:
There are two main transport layer protocols of TCP/IP protocol suite, TCP (Transimission Control Protocol, Transmission Control Protocol) and UDP (User Datagram Protocol, user Datagram Protocol)
1: introduction of TCP protocol
TCP is a connection-oriented, reliable process-to-process communication protocol.
TCP provides full-duplex service, that is, data can be transmitted in both directions at the same time, and each TCP has a send cache and a receive cache, which is used to store data on a temporary basis.
2: TCP message format 2.1TCP message segment
TCP groups several bytes into a packet to form a message segment.
TCP message segments are encapsulated in IP datagrams.
2.2TCP message segment format
Source port number: 16-bit field, which is the port number corresponding to the sender process.
Destination port number: a 16-bit field that corresponds to the process of the receiver. After receiving the data, the receiver determines which application process to send the data to according to this port number.
Serial number: when TCP receives bytes of data from a process, it stores them in the send cache and numbers each byte.
Confirmation number: the confirmation number is the confirmation message to the sender. Use it to tell the sender that all segments prior to this sequence number have been received. If the confirmation number is X, it means that the previous Xmuri data segment has been received.
Header length: usually 20 bytes, the maximum can be expanded to 60 bytes. It can be used to determine the byte length of the first data structure.
Reserved: as a future extension, it has not been used yet.
Control bits: these six bits play a very important role. The connection, transmission and disconnection of the TCP are all directed by these six control bits. What you mean is as follows.
URG: emergency pointer valid bit. Only 0 and 1, 1, and 1 indicate that the pointer is on. When the data is transferred, it is first put in the cache (memory) and temporarily saved. The emergency pointer bit means that the data can be extracted first in memory.
PSH: the flag bit = 1 requires the receiver to deliver the data segment to the application layer as soon as possible. In PSH=1, data segments are sent directly to the application layer without caching. Priority is higher than URG.
ACK: confirm bit. The confirmation serial number is valid only when ACK=1. When ACK=0, confirm that the serial number field is invalid.
SYN: connection bit. Synchronize the sequence number bit, which is set to 1. 0 when TCP needs to establish a connection.
FIN: disconnect identity. The sender completes the sending task bit, and when the TCP needs to disconnect to complete the data transmission, the disconnected party proposes to set this value to 1. 5.
RST: used when reestablishing a connection TCP connection. When RST=1, notifies you to re-establish the TCP connection
Window size: used to indicate the number of segments that can be received locally. The window size is variable. When the network is unobstructed, the window value becomes larger to speed up the transmission speed, and when the network is unstable, reducing this value can ensure the reliable transmission of network data. The flow control mechanism in TCP protocol depends on the size of the window value.
Checksum: used for error control. When sending the TCP segment, the sender calculates the checksum, and when it arrives at the destination, it calculates the checksum again. If the checksum is consistent twice, the data is basically correct, otherwise the data will be considered to have been destroyed and the receiver will discard the data.
Emergency pointer: used in conjunction with URG, valid when URG=1.
Options: there can be up to 40 bytes of optional information in the header of the TCP.
Three: TCP connection-three-way handshake 3.1 first handshake
Connection establishment process: PC1 sends a connection establishment request with the SYN flag set to 1.
3.2 second handshake
This handshake is actually divided into two parts.
The first part: PC2 receives a request from PC1 and replies to PC1 with a confirmation message. The typical sign of this process is that the ACK control bit of TCP is 1. And confirm that the serial number is the initial serial number of PC1 plus 1.
The second part: PC2 needs to reply after receiving the request. That is, PC2 also sends a request to PC1 to establish a connection. The typical sign of this process is the same as the first handshake, that is, the SYN control bit of TCP is 1.
In order to improve efficiency, the two parts are generally merged into one packet.
3.3 third handshake
PC1 receives a reply from PC2 (including request and confirmation) and needs to reply a confirmation message to PC2. A typical sign of this process is that the ACK control bit of TCP is 1. 0. And confirm that the serial number is the initial serial number of PC2 plus 1.
At this point, the three handshakes are completed.
3.4 Summary
In the picture above
Seq represents the request serial number.
Ack means to confirm the serial number
The SYN control bit is set to 1. 0 only when a connection is requested.
Four: TCP waved four times
Either of the parties participating in the data exchange (client and server) can close the connection. TCP disconnects in four steps, also known as four waves.
4.1 first wave
PC1 sends a TCP message segment with FIN and ACK control bit 1 to PC2.
FIN: disconnect ID, and the party who proposes to disconnect sets this value to 1.
ACK:ACK=1, which confirms that the serial number field is valid.
4.2 second wave
PC2 received a message from PC1 and began to reply.
PC2 replies to ACK=1 's TCP message segment to PC1.
4.3 third wave
PC2 now initiatively sends messages to PC1 and message segments of FIN=1,ACK=1 to PC1.
That is, PC2 also sent a message to PC1,FIN=1. I want to disconnect from you. ACK=1, verify that the serial number field is valid.
4.4 fourth wave
PC1 receives a message from PC2 and replies to ACK=1 's TCP message segment.
ACK=1, confirm that the serial number field sent by PC2 to PC1 is valid.
4.5 semi-closed
During the disconnection of the TCP (four waves), the TCP party (usually the client) can terminate sending data, but can still receive the data and become semi-closed.
Describe it in detail:
1. The client sends that FIN message segment, which half closes the connection, and the server sends the ACK message segment and receives it half closed.
two。 The server continues to send data, while the client only sends ACK acknowledgements and no longer sends any data.
3. When the server sends all the data, it sends the FIN message segment, and the customer sends the ACK message segment, thus closing the TCP connection.
Introduction to DUP Protocol 5.1UDP Protocol
The disadvantage of UDP: it is a transport layer protocol with no connection and no guarantee of reliability, that is, the sender does not care whether the transmitted data reaches the target host, whether the data is wrong, etc., and the host that receives the data will not tell the sender whether it has received the data, and its reliability is guaranteed by the upper layer protocol.
Advantages of UDP: the header of UDP is simple in structure and can achieve minimum overhead in data transmission.
The header format of the 5.2UDP message
UDP has a wide range of applications in practical work. For example, the chat tool QQ uses UDP when sending short messages.
5.3UDP protocol ports and functions
TFTP: simple file transfer protocol, fast.
RPC:: remote procedure call. It is used when transmitting data synchronously.
NTP: for example, in a network architecture, a network time protocol is needed when 100 machines are used to transmit data synchronously.
Six: common protocols and their ports
FTP: file server, convenient for uploading and downloading files.
TELNET: sent in clear text, it is recommended to be used in local area network, not in wide area network.
SMTP: the protocol for sending mail
POP3: an agreement to receive mail
HTTP: the protocol used to open the website
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 269
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.