Search code examples
pythontwistedtransport

how to transport an object in twisted?


I know with "transport.write()" I can transport string object but I want to know is this possible to transport other type of data, something like a python class object ? if It is possible how can I do this?


Solution

  • You can devise some arbitrary custom protocol, but it may be more productive to use a framework that already exists for this purpose, like google's protocol buffers that allow you to easily define an efficient message passing structure, and support python already.

    JSON is an easy alternative, and plenty of people simply use zipped json objects, because its easy and built in to python by default, but the results are slow, have unpredictable size artifacts (zipped is typically larger than uncompressed output for numerous small messages), and are a poor solution for transferring binary data.

    edit: Oh yes, and don't use pickle.