Skip to content Skip to sidebar Skip to footer

Having Trouble With A Simple Twisted Chat Server

When I try and run this (see code below) I get the 'connection made' response from the server and the command prompt to write an input. However when I try and enter the input it ju

Solution 1:

You made a mistake in the client. Basically, server expects to receive lines, meaning data terminated by newline. However, client sends data without newline character at the end.

So, to fix client, just add \r\n to the data:

self.transport.write(data +"\r\n")

Here is client protocol:

classEchoClient(protocol.Protocol):

    defsendData(self):
        data = raw_input("> ")
        if data:
            print"sending %s...." % data
            self.transport.write(data + "\r\n")
        else:
            self.transport.loseConnection()

    defconnectionMade(self):
        self.sendData()

    defdataReceived(self, data):
        print data
        self.sendData()

    defconnectionLost(self, reason):
        print"connection lost"

Post a Comment for "Having Trouble With A Simple Twisted Chat Server"