[Twisted-Python] Twisted and MVC

Christian Scharkus mail.sensenmann at googlemail.com
Mon Dec 15 07:22:38 EST 2008

Well ... you're just right but the code is still closed atm so you have to
be happy with some snippets. I left out unimportant functions and replaced
names with representatives.

The main.py:

import controller


The controller.py:

import model, view

class controller():
    def __init__(self):
        self.model = model.Client(self)
        self.view = view.view(self)

    def startConnection(self,server,port):

    def gotConnection(self):
        print 'connection established'
        self.model.sendHandshake('some hash')

And finaly the model.py:

from twisted.internet import reactor, protocol, task, ssl
from twisted.protocols import basic

class Client(basic.LineOnlyReceiver, protocol.Factory):

    def __init__(self,controller):
        """Takes one argument: the instance of the controller Class."""

    def startConnection(self,server,port):
        """Initiate the connection."""
        reactor.connectSSL(server, port, self, ssl.ClientContextFactory())

    def buildProtocol(self, addr):
        return self

    def connectionMade(self):

    def sendHandshake(self,hash):
        """The Handshake has to be send first, after a ssl connection is
        self.sendLine('line to that the server respond with another line')

    def lineReceived(self,data):

2008/12/15 Valentino Volonghi <dialtone at gmail.com>

> On Dec 14, 2008, at 9:38 PM, Christian Scharkus wrote:
> methods of the instance and send messages to the server. So how do I
> connect
> the model to he server? In former implementations I were using the
> Clientfactory but this didn't work very well.
> <mode yoda>
> Use the code Luke
> </mode yoda>
> Without showing the code it's hard to give an help. Anyway it's the
> responsibility of the protocol to translate a line into a controller call,
> and the controller should then consider calling something on the
> model but again without the code it's pretty hard to guess which is
> edge A5 and which is panel G3. :)
> --
> Valentino Volonghi aka Dialtone
> Now running MacOS X 10.5
> Home Page: http://www.twisted.it
> http://www.adroll.com
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20081215/cc06a111/attachment.htm 

More information about the Twisted-Python mailing list