Tom
Tom

Reputation: 19302

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 equivalent flag in Windows? Alternatively, how can I do non-blocking sendto/recvfrom in Windows?

Upvotes: 4

Views: 4658

Answers (1)

phihag
phihag

Reputation: 288070

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.

Upvotes: 5

Related Questions