[Twisted-Python] Protocol dataReceived

Bob Ippolito bob at redivi.com
Wed Mar 12 17:46:17 EST 2003

On Wednesday, Mar 12, 2003, at 07:51 America/New_York, Philippe 
Lafoucrière wrote:

> Hello,
> I hav a question about twisted.protocol. I want to create a new 
> server, with
> its own protocol.
> this would be :

Basically what you want to do is look at twisted/protocols/basic.py -- 
specifically Int16StringReceiver (to see how to read in a 
length-prefixed string chunks at a time), NetstringReceiver (an example 
of having multiple states), and StatefulStringProtocol (this pattern 
will be useful for implementing your commands).

> The problem is that data1, data2, datan, would be binary data.
> I am not sure that it won't pose a problem in strings used with 
> protocol
> (such end of string).

Python strings are entirely 8-bit safe, for example len('\x00hi\xff') 
== 4 is a true statement.. so that will not cause you problems unless 
the transport has problems with it (i.e. a serial port or tty not 
explicitly configured to be 8bit clean may cause problems, and TCP/UDP 
sockets as a transport will never have this problem).


More information about the Twisted-Python mailing list