It seems like I often have a need to work with a simple TCP protocol whose messages have a header which starts with the length of the message and an integer representing the message type (OpenFlow is one of many such protocols). To save myself the trouble of creating and debugging a very similar custom implementation each time I have this need, I decided to package it as a simple Python framework which does this for me. It is based on the event-driven Twised networking engine. Using this simple extension on top of Twisted has a number of benefits:
- Automatic handling of the length and type fields when sending and receiving messages.
- Automatic unpacking of messages based on type.
- Client automatically tries to reconnect if the connection is lost.
- Server can handle any number of clients simultaneously.
You can view the official package on the PyPi website here. My local page for the package is here — please view it for an example on how to use this package.