[英]UDP is not reliable at all?
I have designed a system in which i used UDP to send broadcast messages to some clients connected to the same Access point. 我设计了一个系统,在该系统中,我使用UDP向与同一访问点连接的某些客户端发送广播消息。 I am using an Access point to connect the server and all other clients.
我正在使用访问点连接服务器和所有其他客户端。 The problem is with the broadcasting.
问题出在广播上。 When i broadcast say a message of 800 bytes to the clients, reception is totally random.
当我向客户端广播一条800字节的消息时,接收完全是随机的。 Sometimes clients are able to get the messages and sometimes not.
有时客户可以获取消息,有时则不能。 I tried to broadcast it multiple times so that at-least one will go through and reach all the clients.
我尝试过多次广播,以便至少通过一次广播并覆盖所有客户。 But even this is not working some times.
但是,即使这样有时也不起作用。 Why are packets getting dropped?
为什么丢包? Any problem with the size of packets ?
数据包大小有问题吗? How should i go about to make it reliable ?
我应该如何使其可靠? What factors may lead to this?
哪些因素可能导致这种情况? I have 40-50 clients connected to the AP.
我有40-50个客户端连接到AP。 The Access point is exclusively used for this Application and there is no Internet connection to it.
接入点专用于此应用程序,并且没有Internet连接。
UDP is inherently unreliable in the sense that: 在以下方面,UDP本质上是不可靠的:
Why are packets getting dropped?
为什么丢包?
In general, there are a number of possible reasons: 通常,有多种可能的原因:
Any problem with the size of packets?
数据包大小有问题吗?
Yes. 是。 If a UDP packet is too large, it may need to be fragmented (at the IP packet level).
如果UDP数据包太大,则可能需要分段(在IP数据包级别)。 If any of the fragments gets lost, then the receiver cannot reassemble the packet, and the entire UDP packet will be lost.
如果任何碎片丢失,则接收方无法重组数据包,并且整个UDP数据包都会丢失。 (There is no mechanism for retransmitting the lost fragments.)
(没有重新传输丢失的碎片的机制。)
Reference: http://pcvr.nl/tcpip/udp_user.htm#11 . 参考: http : //pcvr.nl/tcpip/udp_user.htm#11 。
Hence, the probability of a large UDP packet getting lost is greater. 因此,大UDP数据包丢失的可能性更大。
Note that fragmentation occurs when the IP packet size exceeds the MTU of a link. 请注意,当IP数据包大小超过链接的MTU时,就会发生分段。 For an Ethernet link, the MTU is typically ~1500 octets or more.
对于以太网链路,MTU通常约为1500个八位位组或更多。 But the IPv4 spec allows the MTU to be as low as 576 octets.
但是IPv4规范允许MTU低至576个八位位组。 If you subtract the size of the IP and UDP headers, that gives a minimum UDP packet payload size of 534 octets before fragmentation is possible.
如果减去IP和UDP标头的大小,则在可能进行分段之前,UDP数据包的最小有效载荷大小为534个八位位组。
How should i go about to make it reliable ?
我应该如何使其可靠?
These things may help: 这些事情可能会有所帮助:
But nothing will make UDP reliable in the sense above. 但是,从上述意义上讲,没有什么能使UDP可靠。 The protocol is inherently unreliable.
该协议本质上是不可靠的。 If you want reliability, either use TCP or implement your own reliability mechanisms at the application protocol level.
如果需要可靠性,请使用TCP或在应用程序协议级别实现自己的可靠性机制。 The former is probably the better approach.
前者可能是更好的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.