[Twisted-Python] Need help pulling things together.

Matt Hubbard m.hubbard at imperial.ac.uk
Fri May 25 05:19:35 MDT 2007


Brendon Colby wrote:
> With all the different examples I'm having a hard time finding the
> "right" way to write my server using Twisted. I thought I was on to
> something reading through the IRC server protocol, but without a full
> server example I got lost. Do I set up a generic handleCommand() like
> interface and define each command in the protocol class (i.e.
> do_sendMessage) and have callbacks that my User class
> redefines/implements? Or am I on the right path?
> 
> I really appreciate any input on this!


Hi Brendon,

I'm having a hard time working out what you've got and where you're trying to go.

I think you're asking where you should you place the abstraction between data from lineReceived and executing specific commands based on that data. I shall respond with the caveat that I'm not qualified to speak for the "right twisted way", but I hope I can be of some assistance.

The first answer that springs to mind for most of your questions is "depends on what you're trying to achieve with your project".

Where to place an abstraction layer is something that I often end up hitting my head against, and generally I've found this to be time-wasting vacillation.

I'd honestly recommend you get on and code your management of users and of areas and worry about the abstraction layer later. Sitting around postulating doesn't get any code written and re-factoring small projects doesn't take that long.


If it were me and I was writing a telnet-based chat server, I would probably separate chat messages from commands and make this distinction in the protocol. I'd handle command interpretation in the User class.

class ChatProtocol......
    def lineReceived(self,line):
        if line[0] == '/':
            self.user.cmdReceived(line[1:])
        else:
            self.user.msgReceived(line)


I hope this helps. Please point out if I've entirely misinterpreted your question.

Cheers,
Matt.




More information about the Twisted-Python mailing list