[Twisted-Python] Sending jpeg data over TCP/IP
Glyph Lefkowitz
glyph at twistedmatrix.com
Wed Feb 24 09:31:50 EST 2010
On Feb 22, 2010, at 9:13 AM, Christopher Armstrong wrote:
> On Mon, Feb 22, 2010 at 2:03 AM, gary clark <burslem2001 at yahoo.com> wrote:
>> The correct way I think is to use base64 and just one connection after more research. Good to research.
>>
>> Thanks,
>> Garyc
>
> No, base64ing file contents is a terrible thing to do if you're
> already writing your own TCP-based protocol. Just length-prefix the
> data.
In Twisted, lots of classes exist to help you do this. For simple length prefixing, have a look at any of the *stringReceiver classes in twisted.protocols.basic. (NetstringReceiver, Int32StringReceiver, etc)
You can transmit binary data over many higher-level protocols as well; HTTP can handle binary entity-bodies just fine, as can twisted's "native" protocools, PB and AMP.
More information about the Twisted-Python
mailing list