pythonudp接收器是否总是只接收一条消息?

2024-09-28 01:31:17 发布

您现在位置:Python中文网/ 问答频道 /正文

关于UDP接收器。
考虑下面的示例代码,我是否必须考虑在recfrom方法中可能收到多个UDP消息?

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(("", 99))
while 1:
    data, addr = s.recvfrom(1024)
    someFunction(data)

Tags: 方法代码import消息示例databindsocket
1条回答
网友
1楼 · 发布于 2024-09-28 01:31:17

对标题中的问题没有。在

是的!对问题中的问题。UDP数据包通常到达两次(而且是无序的)。在

维基百科说:

UDP uses a simple transmission model with a minimum of protocol mechanism. It has no handshaking dialogues, and thus exposes any unreliability of the underlying network protocol to the user's program. As this is normally IP over unreliable media, there is no guarantee of delivery, ordering or duplicate protection. UDP provides checksums for data integrity, and port numbers for addressing different functions at the source and destination of the datagram.

相关问题 更多 >

    热门问题