select 模块中的 select.select() 函数是否将与 UDP 函数一起工作 - recvfrom() 和 sendto( )? 我想让程序使用 select 函数,并且我知道它可以与 TCP 函数一起使用 - send 和 recv 但我想构建使用 select 函数的 UDP 服务器。
那么,是否可以将 select 函数与 UDP 函数 recvfrom 和 sendto 一起使用?
请您参考如下方法:
是的,Python 的 select() 函数适用于 UDP 和 TCP 套接字。为了解决您对 user_ABCD 的评论中的后续问题,使用 UDP 套接字,select() 返回与使用 TCP 套接字时相同的信息。
来自documentation :
The return value is a triple of lists of objects that are ready: subsets of the first three arguments. When the time-out is reached without a file descriptor becoming ready, three empty lists are returned.
如果您将包含 UDP 套接字的参数传递给 select(),则这些套接字将包含在返回列表中,前提是它们实际上已准备好读取或写入。
