[Twisted-Python] Building a TCP server, having issues

Sofiane Akermoun akersof at gmail.com
Mon Feb 18 07:46:42 EST 2013


As wrote Phil Mayers LinReceiver is a nice protocol helpers for you.
All the commands use a CRLF delimiter and for your logic it is easy to
know when a command is fully received or if you need to wait for more
As wrote Glyph dataReceived (or lineReceived) Should only use to
received data, sanitize them like gather the command name, and the
arguments, and pass it to another big function named handleCommand
that will use the big if/else condition to know what to do.


Sofiane Akermoun

2013/2/18 Phil Mayers <p.mayers at imperial.ac.uk>:
> On 02/17/2013 01:09 AM, Adam Heller wrote:
>> Glyph,
>> I will definately look into that.  As far as the server spec, it's over
>> TOR (This part of the 'competition' has since closed, but feel free to
>> catch up: http://uncovering-cicada.wikia.com/wiki/Uncovering_Cicada_Wiki
>> and
>> http://mentalfloss.com/article/31932/chasing-cicada-exploring-darkest-corridors-internet
>> (from last year's 3301).  I'm simply trying to do the python thing and
>> move classes around instead of trying to reinvent the wheel [dh() is a
>> rudimentary Diffie Helman key exchange] : "
>> In the programming language of your choice build a TCP server
>> that implements the protocol below. The server code must be written by
>> you and you alone, although you are free to use any modules or libraries
>> publicly available for the selected programming language. Once you have
>> done this, make it accessible as a Tor hidden service. Then provide us
>> with the onion address and port via a GPG-encrypted email to this
>> address. You have until 0:00 UTC on 3 Feb, 2013. Any emails received
>> after that time will be ignored. Good luck. 3301
>> ==================================================================== 1.
>> INTRODUCTION The TCP server MUST listen on an arbitrary port, and send
>> and receive plain text with lines separated by <CRLF>
> Glyph has already mentioned the buffering and state machine options, but
> since it's a line-based protocol, you chould also look at
> t.p.basic.LineReceiver:
> http://twistedmatrix.com/documents/current/api/twisted.protocols.basic.LineReceiver.html
> ...which does the buffering for you and calls a method with full
> "lines". You may want to look at the source for that class' dataReceived
> method, for an example of how it does the buffering Glyph talks about.
> There are other examples of doing state machine dispatch in the Twisted
> sources, but it's a pretty simple technique - set a "state" variable,
> and a big if/then clause (or, for performance, a dict of state->handler)
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

akersof at gmail.com

More information about the Twisted-Python mailing list