On Mon, Feb 3, 2020 at 8:06 PM Go Luhng <golu...@gmail.com> wrote: > > Hi there, > > I'm planning to use Twisted to write a client for the following protocol: > > Each messages is composed of two separate messages: > > 1. A header, which is a serialized C struct, containing multiple > fields, among them a `length` field. > 2. A Protocol Buffer payload, which length is specified by the > aforementioned `length` field on the header. > > While the initial implementation is focused on TCP, I do hope to > support this same protocol over UDP eventually. > > What's the best way for me to implement such a client with Twisted? > Specifically, to implement support for sending/receiving messages in > the above format to/from a server? > > Thanks, Go
Assuming the header has a fixed length, https://twistedmatrix.com/documents/current/api/twisted.protocols.basic.IntNStringReceiver.html and its more-concrete subclasses are a decent source of inspiration. OTOH, that's for stream protocols, so if you want to eventually handle UDP, it's probably nicer to do the full sans-io thing (https://sans-io.readthedocs.io/) and wire it up with a more-basic Twisted protocol. Well, that's probably the better approach in any case. _______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python