[Twisted-Python] Using twisted with logging.handlers.sockethandler

Doug Farrell dfarrell at mypublisher.com
Wed Nov 21 11:43:14 EST 2007


Thanks for the tip, I'll take a look at the lineReceived method, I think
that will give me a good idea about how to handle the protocol I'm
thinking about.


-----Original Message-----
From: twisted-python-bounces at twistedmatrix.com
[mailto:twisted-python-bounces at twistedmatrix.com] On Behalf Of Atilla
Sent: Tuesday, November 20, 2007 8:31 AM
To: Twisted general discussion
Subject: Re: [Twisted-Python] Using twisted with
logging.handlers.sockethandler

Correct me if I'm not explaining it correct, but:

dataReceived makes no guarantees how mcuh data you'll get - it depends
on many factors, buffers on the sending and the receiving side, the
size of TCP chunks (if it's TCP), etc.  As stated in the docstrings
for the method - you should make sure your methods works for chunks of
various size, down to the minimum that can come.

What I do is - I model it as a small state-machine that keeps a local
buffer of the data (with an upper bound), trying to construct a
message that's meaningful for my protocol, and when it does - it calls
a method that expects a full protocol packet, that I handle from there
on.

For a good example you can take a look at the lineReceived
implementation, from the actual twisted package. The code and the
docstrings are amazingly useful that way.

_______________________________________________
Twisted-Python mailing list
Twisted-Python at twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python




More information about the Twisted-Python mailing list