Twisted: How to sendLine from outside the LineReceiver class?

Qp qp at al.net
Sun Feb 29 14:06:07 EST 2004


Hello.  I'm building a simple chat server and client interface, and I've got
everything working except for this:

While the client's basic.LineReceiver protocol class can sendLine when a
connection is made (that is, when the class is called automatically),
whenever I try to call sendLine from another class (my ClientFactory class)
then I get the following error.

"in sendLine
return self.transport.write(line + self.delimiter)
AttributeError: 'NoneType' object has no attribute 'write'"

So, I assume the instance of the LineReceiver is not set up properly.  How
do I do this?

The code I am using for the classes is as follows.  The error comes when I
call chatFactory.sendMessage():

>>>
class chatClient(basic.LineReceiver):

    def connectionMade(self):
        self.sendLine("A new person has entered the room!")

    def lineReceived(self, line):
        app.text_output.config(state=NORMAL) #enable text_output for insert
        app.text_output.insert(END, line +"\n")
        app.text_output.config(state=DISABLED)
        app.text_input.delete(0, END) #clear text_input
        app.text_output.see(END) #move scrollbar to the bottom

    def connectionLost(self, reason):
        reactor.stop()

class chatFactory(protocol.ClientFactory):
    protocol = chatClient

    def clientConnectionFailed(self, connector, reason):
        reactor.stop()

    def clientConnectionLost(self, connector, reason):
        reactor.stop()

    def sendMessage(self):
        c = chatClient()
        c.sendLine("Hey there")
<<<






More information about the Python-list mailing list