On Saturday 14 March 2009 19:54:04 Shelby Ramsey wrote:
> Peter,
>
> Thanks for the quick response.  The issue isn't grabbing the content length
> ... but rather grabbing the body ...
>
> The protocol is TCP so the text (not binary) comes in streams ... so the
> body is / might be broken into streams ... so I'm trying to figure out how
> to "receive" the content length so I can get a complete body from different
> streams.

Still not sure if I understand -- with TCP, there is always just one stream, 
and so its just a matter of breaking up the stream into suitable chunks.  

And in your case, it seems you have something like HTTP, ie. some header lines 
including Content-Length: and then the body, is that correct?

If that is the case, the twisted.protocols.basic.LineReceiver class might be a 
good starting point. To use it, you make your Protocol handler a subclass of 
LineReceiver; the reactor then calls your protocol objects' lineReceived() 
method with new data as long as you stay in "line mode". Switch into "raw 
mode" to receive the body of the message. With HTTP for example, this would be 
after you receive an empty line. You do this by calling the setRawmode() 
method which is provided by LineReceiver. From that point on forward, the 
reactor will call the dataReceived() method to hand your protocol object new 
data. Presumably, you've already received a Content-Length header and stored 
that somewhere. Receive Content-Length bytes of data, and call setLineMode() 
to switch into line mode again. 

API docs are 
here:http://twistedmatrix.com/documents/current/api/twisted.protocols.basic.LineReceiver.html

Hm, that would maybe be a good topic for a tutorial.

hth,
peter.



> Thanks again!
>
> SDR

Attachment: signature.asc
Description: This is a digitally signed message part.

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

Reply via email to