[Linux network programming notes] Introduction to transmission protocols TCP and UDP

Source: Internet
Author: User

As this chapter is mainly an introductory topic, I will not talk about it much. Here is an overview of the Internet!

Note] Reprint address: http://www.cnblogs.com/hill/archive/2006/10/12/527499.html

China Mobile and China Unicom have implemented GPRS networks and CDMA networks covering a large number of regions. It is possible to achieve data transmission through wireless networks. Wireless modem uses GPRS and CDMA modules to transmit data through China Mobile and China Unicom's GPRS and CDMA networks, and packets data through the TCP/IP protocol, allowing flexible access to multiple devices, the project is easy to install. In the application of industrial field data transmission, it can solve the problem of data transmission in remote areas without network or telephone lines. Compared with traditional digital radio stations, the wireless modem transmission solution is the best choice for modern industrial field data transmission, which is simpler, more flexible, and more operable.
Currently, the data transmission bandwidth of China Mobile and China Unicom GPRS and CDMA networks is about 40 kbps, and is limited by bandwidth, it is best to use the data collection scheme, such as proactive alarms, data Round-Robin collection, and active call-back for alarms, which consume less bandwidth. In addition, considering the support for the real-time data collection solution of the front-end server, the wireless modem transmission solution can only be used as a supplement to the current transmission solution.
With the continuous development of wireless communication technology, the bandwidth of wireless transmission data will continue to increase. with 3G wireless networks, the bandwidth of data transmission will reach 2 Mbps, the wireless transmission solution will gradually become the main application solution for monitoring Transmission networking.
At present, due to the inherent characteristics of GPRS and CDMA, GPRS and CDMA are widely used in various fields. However, there is a lot of debate about the use of TCP/IP protocol or UDP protocol in transmission.

The difference between TCP and UDP is described below:
1. Connection-based and connectionless
2. Requirements on system resources (more TCP and less UDP)
3. UDPProgramSimple Structure
4. Stream mode and datagram Mode
5. TCP ensures data correctness, UDP may cause packet loss, TCP ensures data order, and UDP does not guarantee
In addition, let's talk about their differences based on the situation of the GPRS network:
1. TCP transmission has a certain latency, which is about 1600 ms (provided by mobile devices). The UDP response speed is slightly faster.
2. TCP Header Structure
Source Port 16-bit
16-bit Target Port
32-bit serial number
Response No. 32-bit
4-digit TCP Header Length
Reserved 6-bit
ControlCode6 digits
Window Size 16 bits
16-bit offset
16-bit checksum
Option 32-bit (optional)
The minimum TCP packet header size is 20 bytes.

UDP header Structure
Source Port 16-bit
16-bit destination port
16 characters in length
16-bit checksum
UDP packets are much smaller. Indeed, because UDP is a non-reliable connection. The original intention is to send data packets as quickly as possible.

The discussion is very streamlined.

3. GPRS network port resources, UDP is very short, and changes rapidly. TCP adopts reliable link transmission, and there is no problem of port changes. Industrial Applications generally have the following characteristics,

1. It must be transmitted from time to time, but there are also some scenarios where scheduled transmission is required. In general, the server center and GPRS terminal devices must be able to transmit data from time to time throughout the transmission process.
TCP itself is a reliable link transmission, providing a two-way transmission channel from time to time, which can meet the requirements of industrial field transmission. However, the GPRS network also has a limit on the TCP link: this link has no data traffic for a long time (about 20 minutes, depending on the actual situation, the priority of this link is automatically lowered until the link is forcibly disconnected. Therefore, the heartbeat packet (usually one byte of data) is used to maintain the link.
Due to its own characteristics and the limited resources of the UDP port in the GPRS network, UDP is easy to change when there is no data traffic for a period of time. The impact is to send data from the server center to the GPRS terminal, the GPRS terminal cannot receive the message. The specific reason is that the mobile gateway has transitioned from the port, and a UDP packet needs to be sent to the host every certain time to maintain the IP address and port number, in this way, the host can actively send UDP packets to GPRS and I found in the test that the interval is very short. I can only maintain the UDP packet once in more than one minute, however, the mobile Gateway may lose this port for a long time. If the host wants to send data to GPRS, it will definitely not work. Only the GPRS terminal device sends another UDP packet, move and assign you a transit IP address and port for two-way communication.

2. The packet loss rate is small. In some industrial scenarios, such as electric power, water meter reading, and environmental monitoring, data loss during transmission is not allowed or data reliability is required to the maximum extent. From this point of view, it is clear that in the wireless data transmission process, TCP is better than UDP to ensure data integrity and reliability, and there is a smaller packet loss rate. This is also true in actual tests. Taking the GPRS terminal equipment provided by Xiamen sanrong Technology Co., Ltd. as an example: TCP is deployed at 9 in and UDP is deployed at around 17 in.

3. Cost reduction is required. At present, many GPRS devices are used to replace early-stage radio data transmission stations. In addition to the scope of use, the main consideration is cost. The cost reduction is of course the most acceptable. Directly related to the cost is the traffic, low traffic, and low cost. Although TCP has more headers than UDP, UDP usually needs to maintain two-way channels in actual applications, so it must maintain port resources through a large amount of Heartbeat packet data. In general, the actual traffic of UDP is larger than that of TCP. Many users do not know that UDP requires a large number of Heartbeat packets to maintain port resources in the early stage. Generally, UDP is considered to be more traffic-saving than TCP. In fact, there is a misunderstanding.

4. In some specific application scenarios, such as the time-to-time interaction systems of some banks, the response speed is very high. At this time, the data transmission frequency is fast, and a large number of Heartbeat packets are not required to maintain UDP port resources, using UDP is advantageous.

5. In the current 1: N transmission mode, there are multiple GPRS terminal devices that transmit data to a server center. UDP is much better than TCP at this time, because UDP consumes less system resources. However, in practical applications, it is found that many users still use the TCP transmission mode to establish a second-level Center 1: A (1: N), that is, each sub-center corresponds to N/A devices, data is processed independently and then transmitted to the master center in a unified manner. This not only ensures that the TCP transmission protocol is used in the transmission process, but also well handles the problem of system consumption of multiple links of the central server.
In general, I think the TCP/IP protocol can better meet the requirements of various industries for remote data transmission. It provides a more stable and convenient transmission channel, it meets the requirements of remote data transmission.

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.