In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
One: introduction
The transport layer defines end-to-end connectivity between host applications. The two most common protocols in the transport layer are Transmission Control Protocol (TCP) and user Datagram Protocol (UDP).
II: Overview of TCPTCP
TCP is a connection-oriented transport layer protocol that provides reliable transport services.
TCP is located in TCP? Transport layer of the IP model. It is a connection-oriented end-to-end protocol. As a transmission control protocol, TCP can provide reliable data transmission for the host. TCP needs to rely on network protocols to provide available transport protocols for hosts. Two hosts need TCP to establish a reliable transmission channel between them before communicating.
TCP port number
TCP allows a host to run multiple application processes at the same time. Each host can have multiple application ports, and each combination of port numbers, source and destination IP addresses uniquely identifies a session.
Some network services use fixed ports, which are called well-known ports, and the port number ranges from 0 to 1023. The rest are dynamic ports.
TCP header
Source port, destination port: processes on the computer need to communicate with other processes through the computer port, and a computer port can only be occupied by one process at a time, so by specifying the source port and the destination port, you can know which two processes need to communicate. The source port and destination port are represented by 16 bits, and the number of ports of the computer can be calculated to be 2 ^ 16.
Serial number: the number that represents the first byte of the data sent in this paragraph. Each byte of the byte stream transmitted in the TCP connection is numbered sequentially. Because the sequence number is represented by 32 bits, every 2 ^ 32 bytes, the sequence number is wound back, starting at 0 again.
Confirmation number: the number of the first byte of data that the receiver expects to receive from the sender's next message segment. That is, tell the sender: I hope the number of the first byte of the data you send next time is this confirmation number.
Data offset: indicates the length of the head of the TCP message segment, with a total of 4 digits. Since the TCP header contains an option with variable length, you need to specify how long the TCP message segment is. It indicates how far the data start of the TCP segment is from the beginning of the TCP segment. The unit of this field is 32 bits (that is, 4 bytes as the unit of calculation), and the maximum of 4 bits represents 15, so the data offset is the maximum 60 bytes of the TCP header 76.
TCP header
URG: indicates whether the data sent in this paragraph contains emergency data. The following emergency pointer field (urgent pointer) is valid only when URG=1
ACK: indicates whether the previous confirmation number field is valid. ACK=1, which means it is valid. The previous confirmation number field is valid only when ACK=1. TCP stipulates that after the connection is established, the ACK must be 1, and the TCP message segment with the ACK flag is called the acknowledgement message segment.
PSH: prompt the receiving application to read the data from the TCP receive buffer immediately to make room for receiving subsequent data. If 1, it means that the other party should immediately submit the data to the upper layer application instead of caching it. If the application does not read the received data, it will stay in the TCP receive buffer all the time.
RST: if you receive a RST=1 message that there is a serious error in the connection to the host (such as a host crash), you must release the connection and then re-establish the connection. Or it indicates that there is a problem with the data sent to the host last time, and the host refuses to respond. The TCP message segment with the RST flag is called the reset message segment.
SYN: used when establishing a connection to synchronize sequence numbers. When SYN=1, ACK=0, it means that this is a message segment requesting to establish a connection; when SYN=1, ACK=1, the other party agrees to establish a connection. SYN=1, indicating that this is a message requesting or agreeing to establish a connection. The SYN is set to 1 only in the first two handshakes, and the TCP message segment with the SYN flag is called the synchronous message segment.
FIN: notifies the other party that the connection is about to be closed and marks whether the data has been sent. If FIN=1, that is, tell the other party: "my data has been sent, you can release the connection". The TCP message segment with the FIN flag is called the end message segment.
Window size: indicates the amount of data that the other party is now allowed to send, that is, the amount of data that the other party is allowed to send from the confirmation number of this paragraph.
Checksum: provides additional reliability
Emergency pointer: marking the location of emergency data in the data field
Option part: the maximum length can be calculated according to the length of the head of TCP. TCP first
The degree of ministerial is expressed in 4 digits, and the longest part of the option is: (2 ^ 4-1) * 4-20cm 40 bytes
TCP to establish a connection (key)
TCP is a reliable, connection-oriented full-duplex transport layer protocol.
The establishment of a TCP connection is a three-way handshake. As shown in the figure
1 the client sends a segment that identifies SYN, indicating that a connection is expected to be established with server A, and the serial number of the segment is a.
2 the server replies with the data segment identified by SYN+ACK, the serial number of this segment is b, and the confirmation serial number is axi1, which is used as a confirmation of the SYN leopard print of host A.
3 Host A sends a segment that identifies SYN, the sequence number of this segment is aqum1, and the confirmation serial number is bread1, which is used as an acknowledgement of server A's SYN segment.
TCP transmission process
TCP uses acknowledgement technology in the transmission process to ensure that the destination device receives the data sent from the original device and is accurate.
How it works:
When the destination device receives the data segment sent by the original device, it will send an acknowledgement message to the source end. After receiving the acknowledgement message, the source device will continue to send the message, which is repeated.
TCP flow control
TCP sliding window technology realizes the data transmission between end-to-end devices for flow control by dynamically changing the window size.
When the client sends data to the server, it sends four segments with a length of 1024 bytes, so the client's window size is 4096 bytes. As a result, the server received the third
After two segments, the cache is full and the fourth segment is discarded. The server resizes its window to 3072 bytes (that is, 3 segments), indicating that the server's cache can only handle 3072 bytes of data segments. So the client changes its window size and sends a data segment with a window size of 3072.
TCP closes the connection
TCP supports data transmission in full-duplex mode, which means that data can be transmitted in both directions at the same time. Before retransmitting the data, TCP actually establishes a link in both directions through a three-way handshake, so after the transmission is complete, the connection in both directions must be closed.
The status in the figure above:
CLOSED does not have any connection status
LISTEN snooping status, waiting for connection requests from remote TCP ports
After sending the connection request, SYN-SENT waits for the other party to confirm
SYN-RECEIVED waits for confirmation after receiving and sending a connection request
ESTABLISHED represents the establishment of a transmission connection, and both parties enter the state of data transmission.
FIN-WAIT-1 shuts down actively, and the host has sent a request to close the connection, waiting for the other party to confirm.
FIN-WAIT-2 shuts down actively, and the host has received confirmation from the other party to close the transmission connection, waiting for the other party to send a request to close the transmission connection.
TIME-WAIT completes two-way transmission connection closes, waiting for all packets to disappear
CLOSE-WAIT passively closed, received a request to close the connection from the other party, and confirmed that LAST-ACK passively closed, waiting for the last closed transmission connection confirmation, and waiting for all packets to disappear
Both sides of the CLOSING try to close the transmission connection at the same time, waiting for each other to confirm.
Close the connection process:
1 when the client performs an active shutdown, it sends an end message segment to the server and the connection enters the FIN_WAIT_1 state. If the client receives a confirmation segment from the server dedicated to the confirmation purpose, the connection is transferred to the FIN_WAIT_2 state. When the client is in the FIN_WAIT_2 state, the server is in the CLOSE_WAIT state, which is a pair of states in which half-shutdown may occur. At this point, if the server also closes the connection (sending the end message segment), the client will confirm and enter the TIME_WAIT state.
2 the client may enter the TIME_WAIT state directly from the FIN_WAIT_1 state (without going through the FIN_WAIT_2 state), provided that the server in the FIN_WAIT_1 state directly receives the end message segment with acknowledgement message (instead of receiving the acknowledgement message segment first and then receiving the end message segment).
3 the client in the FIN_WAIT_2 state needs to wait for the server to send the end message segment before it can transfer to the TIME_WAIT state, otherwise it will stay in this state all the time. If it is not to continue to receive data in the semi-closed state, it is not beneficial for the connection to stay in the FIN_WAIT_2 state for a long time. The situation where the connection stays in the FIN_WAIT_2 state may occur when the client performs a semi-shutdown and forcibly exits before waiting for the server to close the connection. At this point, the client connection is taken over by the kernel, which can be called an orphan connection (similar to an orphan process).
Overview of UDPUDP
UDP is a connectionless transport layer protocol, and the reliability of transmission is not guaranteed. When the application program does not require high transmission reliability, but high transmission speed and delay, UDP protocol can be used instead of TCP protocol.
UDP header
UDP transmission process
Working at the transport layer
Provide unreliable network access
Non-connection oriented protocol
Limited error checking
High transmission performance
Myriad data recovery features
When using UDP to transmit data, the application provides the functions of thermal insulation and arrival confirmation, sorting, flow control and so on.
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: 0
*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.