The computer network knowledge point combing of interview must test

Source: Internet
Author: User
Tags ack socket valid port number
the computer network knowledge point combing of interview must test Transport Layer Overview

Function: The transport layer provides communication services for the application layer above it.

In the OSI seven-layer reference model, the transport layer is the highest level of communication-oriented and the bottom of user functionality.

Two important functions of the transport layer: multiplexing and separation.

Multiplexing: On the sending side, multiple application processes are common to one transport layer;

Split: At the receiving end, the transport layer assigns data to different application processes based on the port number.

and the Network layer difference:

The network layer provides communication services for different hosts, while the Transport layer provides communication services for different applications of different hosts.

The network layer only detects the error of the packet head, and the transmission layer detects the error of the whole message. UDP (User Datagram Protocol) detailed features of UDP

UDP only adds a small amount of functionality on the basis of the IP datagram service: Multiplexing and splitting, error detection for the entire message.

UDP is non-connected

There is no need to establish a connection before communication ends without releasing the connection.

UDP is not reliable.

It is a best effort delivery and cannot ensure that every datagram is delivered.

UDP is message-oriented

The so-called "message-oriented" means: the UDP data transmission unit is the message, and does not make any data splitting and splicing operation.

On the sending side, the application gives the transport layer UDP what data, UDP does not slice the data, only adds a UDP header and gives it to the network layer.

At the receiving end, after UDP receives the datagram of the network layer, the header of the IP data is removed and handed over to the application layer, and no stitching is done.

UDP does not have congestion control

UDP always sends data at a constant rate and does not adjust the transmit rate based on network congestion. This approach has advantages and disadvantages.

Cons: Some messages may be lost when the network is congested, so UDP is unreliable.

Advantages: Some use scenarios allow the loss of messages, such as: live, voice calls, but the real-time requirements are very high, at this time, UDP is still very useful.

UDP supports a pair of one or one-to-many, many-to-many, many-to-one communications

TCP only supports one-to-two communication.

UDP header overhead is small, only 8 bytes.

The TCP header is much more efficient than TCP at least 20 bytes.

PS: Q: What is the specific aspect of UDP that is unreliable. The datagram is missing. The datagram order. UDP packet Header


Source Port

Destination Port

Length: The length of the entire datagram

Inspection and: Inspection of the entire datagram and. TCP (Transmission Control Protocol) detailed TCP Features

TCP is a connection-oriented

The connection needs to be established before communication ends and the connection needs to be released.

TCP provides reliable delivery services

The so-called "reliable" refers to: the data sent by TCP is no duplication, no loss, no error, and the order of the sender is consistent.

TCP is a byte-stream-oriented

The so-called "byte-stream-oriented" refers to TCP, in bytes. Although the transmission of data is divided into a datagram, but this is only for the convenience of transmission, the receiving end of the final reception of the data will be the same as the data on the sender side.

TCP provides full-duplex communication

The so-called "full-duplex communication" refers to: The two ends of TCP can be both as the sending side, but also as the receiving end.

A TCP connection can have only two endpoints at both ends

TCP can only provide point-to-point communication, while UDP communicates in any way.

TCP connections and sockets

What is a "TCP connection".

A TCP connection is an abstract concept that represents a link that can be communicated. Each TCP connection has only two endpoints and represents both sides of the communication. And the double hair can be the sender and receiver at any time.

What is a "socket".

The two ends of a TCP connection are two sockets. Socket =IP Address: port number. Therefore, TCP connection = (socket 1, socket 2) = (IP1: Port number 1,IP2: Port number 2) TCP header

The TCP header length has a fixed portion of 20 bytes, the option portion is variable in length, but up to 40 bytes, so the TCP header is between 20-60 bytes.

Source Port and Destination port

A major difference between the transport layer and the network layer is that the transport layer specifies the application process to which the datagram is sent, and therefore requires a port number identification.

Serial number

The ordinal of the first byte of the current TCP datagram data portion. We know that TCP is byte-oriented, it will number each byte sent, and the different datagrams are consecutively numbered.

Because this field is 4 bytes, the [0,2^32-1] bytes can be numbered (approximately 4G), and the sequence number is used, and when the 2^32-1 bytes are sent, the sequence number starts at 0. In general, when 2^32-1 bytes are sent, the preceding bytes are sent successfully, so the serial number can be reused.

Confirmation number

Represents the number of the next byte that is expected to be received when the current host is the receiving end. Also indicates that the current host has received the last byte ordinal +1 correctly.

Data offset (message length)

It indicates the length of the header portion of the data.

Reserved fields

Identifier

TCP has 7 identifiers that represent the nature of the TCP message. They can only be 0 or 1.

Urg=1
When the Urg field is set to 1, the data portion of this datagram contains the emergency information, at which point the emergency pointer is valid. The emergency data must be at the front of the current packet data section, and the emergency pointer indicates the end of the emergency data. such as control+c: This command requires the operating system to immediately stop the current process. At this point, the command is stored at the beginning of the data portion of the packet, and the emergency pointer identifies the location of the command, and the Urg field is set to 1.

Ack=1
The confirmation Number field is valid after the ACK is placed 1. In addition, TCP specifies that all message segments transmitted after the connection is established must have an ACK of 1.

Psh=1
When the receiving party receives the psh=1 message, it immediately delivers the data to the application without waiting for the buffer to be full before committing. Some interactive applications require such functionality to reduce the response time of the command.

Rst=1
When this value is 1 o'clock, indicates that there is a serious problem with the current TCP connection, you must release the reconnection.

Syn=1
SYN is used when establishing a connection. When Syn=1,ack=0, indicates that the current message segment is a connection request message. When Syn=1,ack=1, indicates that the current message segment is a reply message that agrees to establish a connection.

Fin=1
Fin=1 indicates that this segment is a request message to release the connection.

Receive Window Size

This field is used to implement TCP traffic control. It represents the remaining capacity of the receiving window of the current receiver, and when the sender receives the value, it adjusts the sending window to the size of the value. The size of the sending window also determines the send rate, so the receiver can control the sending rate by setting this value. The sending party adjusts the current send window for each datagram it receives.

Inspection and

Used by the receiving side to verify that the entire packet has been faulted during transmission.

Emergency pointers

Used to identify the tail of emergency data.

Option field

The above fields are required for each TCP header, and the option field is optional and has a variable length of up to 40 bytes.
The most common option field is MMS: Maximum message length. TCP Three-time handshake

In the PS:TCP protocol, one end of an unsolicited request is called a "client", and one end of the passive connection is called the "server Side". Both the client and the server can send and receive data after the TCP connection is established.

Initially, both the server and the client are in the closed state. Both parties have to create their own transport control blocks (TCB) before the communication begins.
After the server creates the TCB and passes into the listen state, it prepares to receive the connection request from the client.

First handshake

The client sends a segment of the connection request message to the server. The message segment is syn=1,ack=0,seq=x in the head. After the request is sent, the client enters the syn-sent state.

Ps1:syn=1,ack=0 indicates that the message segment is a connection request message.

Ps2:x the initial sequence number of the byte stream for this TCP communication.
TCP regulation: Syn=1 message segment can not have data parts, but to consume a sequence number.

Second handshake

After the server receives the connection request message segment, if the connection is agreed, a reply is sent: Syn=1,ack=1,seq=y,ack=x+1. When the answer is sent, it enters the SYN-RCVD state.

Ps1:syn=1,ack=1 indicates that the message segment is a connection-agreed response message.

Ps2:seq=y indicates the initial sequence number of the byte stream that is sent when the service side acts as a sender.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.