Python sockets question: socket.MSG_DONTWAIT in Windows
I have a Python app that uses UDP sendto/recvfrom with the socket.MSG_DONTWAIT flag. In Linux and Mac OS X, this works just fine. However, this flag doesn't exist in the Windows environment.
What is the equivale开发者_Python百科nt flag in Windows? Alternatively, how can I do non-blocking sendto/recvfrom in Windows?
socket.setblocking(False)
switches your socket into non-blocking mode on any platform. Call this once on socket creation, and you can remove all the MSG_DONTWAIT
flags.
If you need to switch between blocking and nonblocking I/O (which is usually not the case), call socket.setblocking
every time you want to switch between those two.
精彩评论