Top-down---transport layer

Source: Internet
Author: User
Tags ack

What is the difference between the transport layer and the network layer for end-to-end communication? Task: Responsible for providing services for communication between application processes in two hosts (providing logical communication). Difference:Transport LayerTo run on a different host.ProcessProvides end-to-endThe logical communicationButNetwork Layeris to provideHostBetweenThe logical communication。 One, multi-path decomposition and multiplexing each transport layer has several fields set up in the message section, including the source port number and destination port number.multi-channel decompositionThat is, at the receiving end, the transport layer examines the fields and identifies the receiving socket, and then directs the message to the socket. The way it works can simply be that each socket on the host is assigned a port number, and when the message arrives at the host, the transport layer checks the destination port number in the message segment and directs it to the appropriate socket. Multiplexingis to collect data blocks from different sockets in the source host and encapsulate the first piece of information for each block of data to generate a segment of the packet, and then pass the message segment to the network layer. 1, non-connected multiplexing and multi-channel decomposition

In the transport layer, the non-connected network transmission is done via UDP. Only the source port number and destination port number in the UDP message, a UDP socket is fully identified by a two-tuple containing the destination IP address and destination port number. On the client side, the source port number is the port number of the client process socket, and the destination port number is the server's port number. On the server side, the source port number is the port number of the socket that the server created, and the destination port number is the port number of the client socket.

  Note: when using UDP to transmit a message segment, a UDP socket is fully identified by a two-tuple containing the destination IP address and destination port number. Therefore, if two UDP segments have different source IP addresses and source ports , but have the same source IP address and destination port number , then these two segments will be directed to the same destination process through the same destination port number . The IP address is not described too much, because the IP address is the knowledge of the network layer, so no mention, we now only need to know that the IP address corresponds to a host, and the port number corresponds to a process (or socket) on a host.

2. Connection-oriented multiplexing and multi-channel decompositioninter-process communication between hosts on the network is essentially achieved through sockets。 There is a slight difference between TCP sockets and UDP sockets in the transport layer where connection-oriented network transmissions are used more than TCP, that is,TCP sockets are made up of a four-tuple (source IP address, source port number, destination IP address, destination port number)to identify the.  Thus, when a TCP packet reaches a host from the network, the host uses all 4 values to direct the message segment, that is, to decompose the packets into the appropriate sockets. Unlike UDP, the twowith different source IP or source port numberThe incoming TCP message segment will beREDIRECT to two different sockets。     However, the principle of multiplexing and multi-path decomposition for TCP is roughly the same as for the multiplexing and multiplexing of non-connected UDP.  Think about why TCP multiplexing and multi-channel decomposition should be designed like this? This is because TCP and UDP treat the received data in a different way. We take the example of TCP sockets and UDP sockets on the server, assuming that the server receives the client's data and sends the data back to the client. When a UDP server receives a UDP message segment, it sends the data back to the client based on the source IP and the source port number of the received UDP segment, whichThere is no need to create a new socket to process the segment, and for a TCP server, when it accepts a connection, itgenerate a new socket, and then communicates with the client through a new socket, which is to send the data back to the client through a new socket.because each connection produces a new socket, a connection with a different source IP or source port number is a different connection, corresponding to the new, different sockets that are generated。 Second, UDP UDP (User Datagram Protocol, subscriber Datagram Protocol), it just does the transport layer protocol can do the least work, except MultiplexingAndmulti-channel decompositionand someError DetectionOutside, it hardly ever did anything.   If the Transport layer protocol used by the application is UDP, the application is almost directly dealing with IP. At the same time, UDP is also a non-connected Transport layer protocol, because when using UDP, the sender and receiver of the transport layer entities between the sending and receiving partiesNo handshake, the so-called handshake, is the sender and receiver by sending some specific pieces of message to each other to confirm, so as to prepare for the transmission. UDP provides a simple interface over the network layer and below the application layer. UDP only provides unreliable delivery of data, once it sends the application to the network layer of data sent out, itdo not preserve data backup(so UDP is unreliable datagram protocol), alsodo not ask the receiving Party to reply to receive success confirmation, alsodoes not re-send dataNoprovides flow controlMoreno congestion control available。 UDP only adds multiplexing and data validation (fields) to the head of the IP datagram.

UDP message Segment Structure

As you can see, the UDP header has only 4 fields and each field consists of two bytes.Source port number:The port number that corresponds to the socket of the native (client) application, which the server side can use to send data to the client.Destination port number: The port number that corresponds to the socket for the application process on the server, such as port 80 for HTTP servers.Length:Specifies the total length of the UDP segment of the header and Data section, in bytes, which is the header + data.Inspection and:Error detection is provided, which is a test and is used to determine if the bits have changed when the UDP message segment arrives from the source. In fact, some fields of the IP header are used in addition to the UDP segment when calculating the test. Note that it detects only one segment of the message that has an error, butDoes not correct this error。 Advantages of UDPFrom the UDP overview, we can see that UDP actually does not provide any services, and TCP provides us with very attractive services (such as data backup, retransmission mechanism, traffic control, receive acknowledgement, congestion control, etc.), to achieve a reliable transmission. Why is there still a UDP thing? Every thing has its merits, and many times, the disadvantage of things is precisely its merits.  Why I say so, let's take a look at its advantages below!  1, the application layer can better control the data to be sent and send time. Why is the application layer using UDP better able to control the data and time sent? Because UDP only provides the simplest, least-service service, when the network application process has data to be passed to UDP, UDP will immediately package this data into a UDP segment and deliver it to the network layer to send the data out. Conversely, because TCP provides a variety of mechanisms, especially congestion control, so that one or more links between the source and destination host becomes very congested, the Transport layer TCP sender is curbed, so that real-time application performance such as Internet telephony, videoconferencing, and so on can become poor. Furthermore, TCP will continue to re-send data packets until the destination host receives the message and confirms it, entire areas no matter how long it takes to deliver it reliably.these features of TCP are often unsuitable for some real-time applications, because they usually require sending data at the fastest sending rate, rather than delaying the transmission of the message excessively, and it tolerates some data loss, so it is unnecessary to use TCP, and the use of TCP adds additional burden. 2, no connection established as mentioned above, UDP is a non-connected Transport layer protocol, and TCP has to go through three handshake before starting data transfer. UDP because it is a non-connected protocol, it is possible to transfer data without any preparation, so it does not introduce delays in establishing a connection. SoDNS is running above UDP instead of TCP, because if DNS is running on top of TCP, it can cause too long connection latencies due to excessive connections, which can cause DNS to run slowly. 3, no connection status TCP due to the provision of a variety of reliable transmission services, need to maintain the connection state in the end system. This connection state includes parameters such as receive and send caches, congestion control parameters, sequence numbers, and confirmation numbers. UDP does not maintain the connection state, nor does it track these parameters.  Therefore, a server that uses UDP can support more active clients. 4, packet header overhead is small because UDP provides less service, only provides multi-path decomposition and multiplexing and verification functions, so its first field is small, only 8 bytes, and TCP header has 20 bytes. Third, TCP TCP as a reliable connection protocol, the biggest feature is the connection-oriented, that is, to establish a connection between the sending data, the data transfer process to maintain the connection, after the data is sent to release the connection. On this basis TCP provides reliable transmission:
    1. Reliable delivery: The data transmitted by TCP is error-free, no loss, no duplication, and arrives sequentially;
    2. Full-Duplex communication: Each segment of TCP traffic maintains a send cache and receive cache ;
    3. Byte stream oriented: The TCP protocol regards the application layer data delivered by the upper layer as a series of unstructured byte streams.
Endpoints for TCP connectionsis not the application process in the host, but the application process maintains theSocket Interface(socket) whose basic structure contains "Ip:port"; the TCP message format is as follows:

  • Source port or destination port (2 bytes, respectively): slightly.
  • ordinal (4 bytes): Each byte in a stream of bytes transmitted in a TCP connection is numbered sequentially. The starting sequence number of the transmitted byte stream must be set when the connection is established. the ordinal value in the message segment is the number of the first byte of data sent by this section . For example, a message segment ordinal value is 101, the data total 100 bytes, then the next message segment ordinal value is 201. Because the size of the ordinal is [0,2^32-1], the loop is out of 0, so the ordinal is using the mod2^32 operation.
  • Confirmation Number (4 bytes): expects to receive the ordinal of the first data byte of the next message segment.
  • Data offset (also known as the first ministerial)(4-bit): Indicates how far from the beginning of the TCP header the data at the beginning of the TCP segment is. is actually pointing out the TCP Head Minister . This field indicates the TCP first ministerial degree in a word of 32bit. Because of the TCP option field, the length of the TCP header is variable. Therefore, the unit of data offset is 4 bytes, and the maximum value of the 4-bit binary is 15, which indicates that the first maximum is only 15*4=60 bytes. In fact, the maximum option field is only 40 bytes.
  • Reserved (6-bit): slightly.
  • Emergency Urg: Indicates that the emergency pointer sub-field is valid.
  • Confirm ack: equals 1 o'clock Confirmation Number field is valid. TCP Specifies that the ACK must be set to 1 for all transmission messages after the connection is established.
  • Push push: Indicates that the receiving application process needs to be delivered as soon as possible, no longer waiting for the entire cache to fill up before delivery.
  • Reset rst: equals 1 o'clock indicates a serious error in the TCP connection and must be released and re-established.
  • Synchronous SYN: Used to synchronize serial numbers when the connection is established.
  • Terminate fin: Used to release a connection.
  • Window (2 bytes): This field is used for flow control to indicate the number of bytes the receiver is willing to receive. Because the receiver has a limited receive cache. The window values are dynamically variable.
  • Inspection and (2 bytes): The scope of inspection and inspection includes header and data.
  • Emergency pointer (2 bytes): Indicates the position of the end of the emergency data in the message segment. Emergency data can be sent even if the window value is zero.
  • Option (up to 40 bytes): slightly.
To be continued ..... Computer network note-TCP Layer-macdroid column-Blog channel-csdn.net http://blog.csdn.net/macdroid/article/details/49070185 computer network "six" : Transport Layer-TCP Overview-windhawkgyang-chinaunix blog http://blog.chinaunix.net/uid-26275986-id-4109209.html Computer Network Review notes five Transport Layer _ red Babe _ Sina Blog http://blog.sina.com.cn/s/blog_a7f4cc6101015c32.html

Top-down---transport layer

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.