python udp socket.recvfrom(bufsize[, flags])(从套接字接收数据)
发布日期:2021-05-10 09:05:50 浏览次数:19 分类:精选文章

本文共 1020 字,大约阅读时间需要 3 分钟。

socket.recvfrom(bufsize[, flags])

Receive data from the socket. The return value is a pair (bytes, address) where bytes is a bytes object representing the data received and address is the address of the socket sending the data. See the Unix manual page recv(2) for the meaning of the optional argument flags; it defaults to zero. (The format of address depends on the address family — see above.)

从套接字接收数据。 返回值是一对(字节,地址),其中字节是代表接收到的数据的字节对象,而地址是发送数据的套接字的地址。 有关可选参数标志的含义,请参见Unix手册页recv(2)。 它默认为零。 (地址格式取决于地址系列-参见上文。)

Changed in version 3.5: If the system call is interrupted and the signal handler does not raise an exception, the method now retries the system call instead of raising an InterruptedError exception (see PEP 475 for the rationale).

在版本3.5中进行了更改:如果系统调用被中断并且信号处理程序没有引发异常,则该方法现在重试系统调用,而不是引发InterruptedError异常(有关原理,请参阅PEP 475)。

规律总结

recvfrom()函数每次只接收一个数据报,数据报发送过来以队列形式存储在缓存中(我猜是这样??),然后函数一个个去取,如果recvfrom(BUFSIZE)中BUFSIZE的值小于当前取到的数据报报文长度,就会报这个错误(),如果recvfrom(BUFSIZE)中BUFSIZE的值大于当前取到的数据报报文长度,也就只返回这个报文,不会再往后取了。

上一篇:python struct.unpack()函数(返回一个元组,其中包含根据格式字符串fmt解包的值)
下一篇:python udp socket.sendto(bytes, address)(将数据发送到套接字)

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2025年05月14日 00时43分56秒