0

I am following official Twisted examples about client/server. I am using LineReceiver.sendLine() to send text from client to server. This code works:

def connectionMade(self):
    self.sendLine("Hello, world!")

and I can see it on my server side. But if I add something like this:

def connectionMade(self):
    while self.running:
        command = raw_input(">>")
        if command=="disconnect":
            self.running = False
        else:
            print "sending..."
            self.sendLine(command)
            print "sent."
    self.sendLine("Hello, world!")

I can see both 'sending...' and 'sent', but nothing more. Server receives nothing even though client appears to be sending the data. If I type 'disconnect' everything is being sent at once, including 'Hello, world!'

Hence my question: where does the actual sending takes place? And what to do to achive something like above?

Ashley Medway
  • 7,151
  • 7
  • 49
  • 71
alex
  • 10,900
  • 15
  • 70
  • 100
  • @Jean-PaulCalderone even if it is duplicate, there is no usable solution given. – alex Sep 24 '13 at 15:07
  • Yes, there is. Check the accepted answer. If you don't understand that answer, please comment on it asking what requires clarification. – Glyph Sep 24 '13 at 17:37

1 Answers1

0

LineReceiver has the line-ending delimiter variable. By default it is '\r\n'. So the protocol waits until it sees the delimiter before actually writing the data to the socket.

The raw_input() strips the trailing new line from the input so the protocol never sees the delimiter.

So try sending a new line '\r\n' after the command or append it to the command variable.

Davor Lucic
  • 28,970
  • 8
  • 66
  • 76