[Twisted-Python] how to design protocol.

Jean-Paul Calderone exarkun at divmod.com
Mon Dec 1 08:56:17 EST 2008


On Mon, 1 Dec 2008 15:19:47 +0200, Aydın ŞEN <adigeaydin at gmail.com> wrote:
>Let me explain my problem.. I am building an uploader application using
>twisted. I am using "Protocol" in both side. What is the best way to
>seperate data?
>When i try to call "self.transport.write(data)"  it doesnt send data
>immediately, it is sending with some other datas whic i send them later. Why
>doesnt it send, what for is it waiting?

http://twistedmatrix.com/trac/wiki/FrequentlyAskedQuestions#WhydoesittakealongtimefordataIsendwithtransport.writetoarriveattheothersideoftheconnection

>
>when i some information data I am sending  with '\n' (there is no other '\n'
>in my data) to separate it in the client side but it is getting really
>complicated. When i start to send file there is no problem, first send
>fileSize then read everything and write in a file till fileSize.

I'm not sure what problem you're describing.

>
>I saw FileWrapper in the api but i couldnt find any tip that how it works,
>is it for sending file, is it right way to my goal?

No.  FileWrapper probably isn't going to help you a lot.  It's possible that
twisted.protocols.basic.FileSender will.

>What about sending data like HTTP? What do you think about this way?
>8 #bytes of data
>11111111 #data
>3 #bytes of data
>111 #data
>0 #finished sending data

twisted.protocols.basic.NetstringReceiver (it can send too) might be useful.

>I need your suggestions all about these.
>(some links, documents, tips would be great)
>

Jean-Paul




More information about the Twisted-Python mailing list