当前位置:网站首页>Demo of UDP communication applied to various environments

Demo of UDP communication applied to various environments

2022-07-24 05:59:00 Joey Boye o (* ^ ^ ^ *) o


`

One 、Ubuntu Compile... In environment Demo Code instance

pure C udp Unicast receive and send instances Demo link
udp Multicast Demo Multicast receive and send instance links

Two 、 be based on visual studio 2013 In the environment udp agreement Demo C++

udp unicast Demo vs Links in the environment
udp Multicast Demo vs Links in the environment

summary

UDP yes User Datagram Protocol For short , Chinese name is user datagram protocol , yes OSI(Open System Interconnection, Open system interconnection ) A connectionless transport layer protocol in the reference model , Provide simple and unreliable transaction oriented information transfer services ,IETF RFC 768 [1] yes UDP The formal norms of .UDP stay IP The protocol number of the message is 17.
UDP Deal with the TCP The protocol is also used to process packets , stay OSI In the model , Both are located at the transport layer , be in IP The next level of agreement .UDP Packet Grouping is not provided 、 The disadvantages of assembling and not being able to sort packets , in other words , When the message is sent , It's impossible to know whether it arrived safely and completely .UDP Used to support network applications that need to transfer data between computers . Including the network video conference system, many customers / Server mode network applications need to use UDP agreement .UDP The protocol has been used for many years since it came out , Although its original glory has been covered by some similar agreements , But even today UDP It is still a very practical and feasible network transport layer protocol .
Many applications only support UDP, Such as : Multimedia data stream , No additional data will be generated , Don't resend even if you know that there are broken packets . When transmission performance is emphasized instead of transmission integrity , Such as : Audio and multimedia applications ,UDP Is the best choice . In data transmission time is very short , So that the previous connection process becomes the main body of the whole traffic ,UDP It's also a good choice . [3]
Content
UDP yes OSI A connectionless transport layer protocol in the reference model , It is mainly used in the transmission which does not require the packet to arrive in sequence , The checking and sorting of packet transmission order is completed by the application layer [4] , Provide simple and unreliable transaction oriented information transfer services .UDP The agreement is basically IP The interface between protocol and upper protocol .UDP The protocol is applicable to multiple applications running on the same device .
UDP Provides connectionless communication , And there is no reliability guarantee for the transmission of data packets , Suitable for transmitting a small amount of data at a time ,UDP The application layer is responsible for the reliability of the transmission . frequently-used UDP The port number has :53(DNS)、69(TFTP)、161(SNMP), Use UDP The agreement includes :TFTP、SNMP、NFS、DNS、BOOTP.
UDP The message has no reliability guarantee 、 Sequence guarantee and flow control fields, etc , Poor reliability . But because of UDP Protocol has fewer control options , Small delay in data transmission 、 High data transmission efficiency , Suitable for applications with low reliability requirements , Or applications that can guarantee reliability , Such as DNS、TFTP、SNMP etc. .
function
In order to identify multiple destination addresses on a given host , At the same time, multiple applications are allowed to work on the same host and can send and receive data packets independently , Design User Datagram Protocol UDP.
UDP Use the underlying internet protocol to transmit messages , Same as IP Provide unreliable connectionless packet transmission services . It does not provide message arrival confirmation 、 Sort 、 And flow control .
UDP Helper Can achieve the specified UDP Relay and forwarding of port broadcast message , About to specify UDP The broadcast message of the port is converted into unicast message and sent to the specified server , Act as a relay .

The main features

UDP It's a connectionless protocol , No connection between source and terminal is established before data transmission , When it wants to transfer, it simply grabs the data from the application , And throw it on the Internet as soon as possible . At the sending end ,UDP The speed of data transmission is only affected by the speed of data generated by the application 、 The capacity of the computer and the limitation of the transmission bandwidth ; At the receiving end ,UDP Put each message segment in the queue , The application reads one message segment at a time from the queue .
Because the transmission data does not establish a connection , So there is no need to maintain the connection state , Including sending and receiving status, etc , Therefore, a server can transmit the same message to multiple clients at the same time .
UDP The title of the packet is very short , Only 8 Bytes , be relative to TCP Of 20 In terms of a byte packet UDP The extra cost is small .
Throughput is not regulated by congestion control algorithm , Only affected by the rate of data generated by the application 、 Transmission bandwidth 、 Source and terminal host performance limitations .
UDP It's message oriented . The sender's UDP Message delivered to the application , After adding the header, deliver it down to IP layer . Neither split , It doesn't merge , But keep the boundaries of these messages , therefore , The application needs to select the appropriate message size .
although UDP It's an unreliable agreement , But it's an ideal protocol for distributing information . for example , Report the stock market on the screen 、 Display aviation information, etc .UDP Also used in routing information protocols RIP(Routing Information Protocol) Modify the routing table in . In these applications , If a message is lost , In a few seconds, another new message will replace it .UDP Widely used in multimedia applications .

Protocol comparison
UDP and TCP The main difference between the two protocols is how to achieve reliable transmission of information .TCP The protocol includes a special delivery guarantee mechanism , When the data receiver receives the message from the sender , A confirmation message is automatically sent to the sender ; The sender will continue to transmit other information only after receiving the confirmation message , Otherwise, it will wait until the confirmation message is received . And TCP Different ,UDP The protocol does not provide a guarantee mechanism for data transmission . If a packet is lost during the transmission from the sender to the receiver , The protocol itself does not make any detection or prompt . therefore , Usually people put UDP Protocol is called unreliable transport protocol .
TCP It's a connection oriented transport control protocol , and UDP Provides connectionless datagram service ;TCP With high reliability , Ensure the correctness of the transmitted data , There is no loss or disorder ;UDP Do not establish a connection before transferring data , Do not check and modify datagrams , There's no need to wait for a response , So there will be packet loss 、 repeat 、 Disorder , Applications need to be responsible for all aspects of transmission reliability ;UDP With better real-time , Work efficiency is higher TCP Protocol high ;UDP Segment structure ratio TCP The segment structure is simple , Therefore, the network overhead is also small .TCP The protocol can ensure that the receiving end receives the byte stream sent by the sending end without error , Provide reliable communication services for applications . Communication systems that require high reliability often use TCP To transmit data .

Applicable occasions

In the choice UDP As a transport protocol, we must be careful . In a very unsatisfactory network quality environment ,UDP Protocol packet loss will be more serious . But because of UDP Characteristics of : It is not a connection protocol , Therefore, the consumption of resources is small , The advantage of fast processing speed , So usually audio 、 Video and ordinary data are used in transmission UDP More , Because even if they occasionally lose one or two packets , It will not have a great impact on the received results . For example, we chat with QQ It is used UDP agreement . [7]
The practical application
In the field of field measurement and control , For distributed controllers 、 Monitor, etc , Its application environment is relatively harsh , In this way, different requirements are put forward for the data to be transmitted , Such as real-time 、 Anti interference 、 Safety and so on . Based on this , In field communication , If an application wants to transmit a set of data to another node in the network , May by UDP The process adds the header to the data and sends it to IP process ,UDP The protocol eliminates the process of establishing and removing connections , The retransmission inspection mechanism is cancelled , It can achieve high communication rate .

原网站

版权声明
本文为[Joey Boye o (* ^ ^ ^ *) o]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/205/202207240517206448.html