Reputation: 193
I'm creating a simple socket server using UDP in Python and I want to add some notion of reliability by having the receiver send ACKs. My sender will have to send data and receive these ACKs at the same time. What is the preferred way of doing this? Should I make both a sending and receiving thread, use some kind of nonblocking calls, or something else?
Any help would be greatly appreciated!
Upvotes: 0
Views: 3343
Reputation: 28036
There are a couple solutions for this:
The simplest solution is in stdlib, the SocketServer module which has a UDPServer - you can set handlers for different message types and enable your state machine that way. There's also a bunch of nifty mixins for threads and other behaviors.
Third-party module gevent which uses libevent for async network programming is another solution.
You could write something at the raw socket level with scapy but that puts all the heavy lifting on you, although there are undoubtedly examples of how to do what you want.
Upvotes: 1