Transport layer: UDP protocol

Source: Internet
Author: User

Transport layer: UDP Protocol I, Transport Layer protocol

From the network layer protocol described earlier, the two ends of the communication are both hosts, the IP datagram header indicates the IP address of the two hosts. But from the transport layer, it is a process in the sender host that is exchanging data with a process in the receiving host, so strictly speaking, the communication parties are not the hosts, but the processes in the host. The host often has multiple application processes in the same time with external communication (such as your browser and QQ at the same time running), a host of the AP1 process is the AP3 process of Host B communication, and host a AP2 process is also in the AP4 process with Host B communication. There is a gray bi-directional arrow between the two host's transport layers, which reads "The Transport layer provides logical communication between application processes." Logical Communication : It appears that the data travels horizontally along the two-headed arrows at the transport layer, but is actually transmitted along the dotted lines in the graph through multiple protocol hierarchies.

The TCP/IP protocol stack Transport layer has two important protocols--udp and TCP, and different application processes use either TCP or UDP in the transport layer:

This section first introduces the simpler UDP, and the more complex TCP is discussed in the next section.

Second, port

In the first section we have seen the concept of ports, the role of ports is reflected in the transport layer. Just in the diagram, AP1 and AP3 communication with AP2 and AP4 communication can be transmitted using the same Transport Layer protocol (TCP or UDP), according to IP address or MAC address can only be the data to the correct host, but the specific need to upload to which process, is identified by the port. For example, using both the browser and QQ, the browser occupies 80 ports, and QQ occupies 4000 ports, then sent over the QQ message will be displayed through the 4000 port on the QQ client, and will not be incorrectly displayed in the browser.

The port number has a 0~65535 number, where:

    • Number 0~1023 is the system port number, these port numbers can be queried in the URL www.iana.org, they are assigned to some of the most important TCP/IP applications, the following are some common system port numbers:
Application layer protocol: FTP TELNET SMTP DNS TFTP HTTP SNMP
System Port Number: 21st 23 25 53 69 80 161
    • Number 1024~49151 to register the port number , for applications that do not have a system port number, the use of such port numbers must be registered in the IANA as required to prevent duplication.

    • Number 49152~65535 is the ephemeral port number , which is left to the client process for temporary use, and after the end of use, such port numbers are released for use by other programs.

Iii. Overview of UDP

UDP (user Datagram Protocol) User Datagram Protocol, which only adds a little bit of functionality on top of the IP datagram service, and its main features are:

    • (1). UDP is non-connected and does not need to establish a connection (while TCP is required) before sending the data, reducing overhead and latency.

    • (2). UDP does its best to deliver and does not guarantee delivery reliability.

    • (3). UDP is message-oriented, for the IP datagram delivered from the network layer, only a very simple package (8-byte UDP header), the first overhead is small.

    • (4). UDP has no congestion control and the sender does not reduce the sending rate when there is network congestion. This feature is important for some real-time applications, such as IP telephony, video conferencing, and so on, which allow for the loss of some data when congestion occurs, because if you do not discard this data, it is most likely to cause a delay accumulation.

    • (5). UDP supports a pair of one or one-to-many, many-to-one, and many-to-many interactive communications.

From the application layer to the transport layer, then to the network layer at various levels of encapsulation:

Iv. UDP Messages

A UDP datagram can be divided into two parts: the UDP header and the data part. The data is part of the data that is delivered by the application layer. The UDP header has a total of 8 bytes, and these 8 bytes are divided into 4 fields:

    • (1) The source port 2 bytes in the other side need to reply to be available, not required when the full 0;

    • (2) The destination port 2 bytes must, is also the most important field;

    • (3) length 2 bytes length value includes header and data part;

    • (4) Checksum 2 bytes is used to verify that the UDP datagram has errors in the transmission process, and the error is discarded.

V. tcpdump fetching UDP Packets

Now let's practice, try to crawl a UDP datagram, and interpret its contents. We need a small program to send a UDP datagram with a specified content to the specified port of the specified IP address , which is already written, enter the following command in turn, download it using GitHub, and compile:

cd Desktopgit clone http://git.shiyanlou.com/shiyanlou/tcp_ip_5cd tcp_ip_5gcc -o test test.c

This C program sends a "HELLO" message to Port 7777 of the IP address 192.168.1.1 . You can use the editor to modify the program to send different content to different IP IP.

Do not run after compiling, we also need to use a well-known grab kit tool tcpdump , enter the following command to install, and run Tcpdump:

updatesudo apt-get install tcpdumpsudo tcpdump -vvv -X udp port 7777

Now minimize the current terminal, open a terminal, and enter the following command to run the C program test that you just compiled:

cd Desktop/tcp_ip_5./test

Test program run end, return to the terminal just running tcpdump view the results of the capture package:

Transport layer: UDP protocol

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.