1

I am trying to develop a mixed protocol which can return a raw response or a Line Based response based on the request. My code looks like

class Receiver(LineReceiver):
def lineReceived(self, line):
    (command, args) = self._parse_command(line)
    result = self.exec_command(command, args) #Secret sauce returns list or blob.
    if  isinstance(result, basestring): # won't work in 3.0 ; least of my worries.
        self.sendLine(str(len(result))) # Sends no. of bytes as a line.
        self.transport.write(result)   #followed by bytes. This is not received by the client.
        self.transport.loseConnection()
    else:
        no_lines = len(result)
        self.sendLine(str(no_lines)) 
        for r in result:
            self.sendLine(str(r))

In the above code transport.write(...) does not send across any data to the client. How can I fix this.

sheki
  • 8,991
  • 13
  • 50
  • 69
  • 4
    Why? This looks like an overly complicated protocol. When possible, you should avoid inventing new protocols and re-use an existing one. – Jean-Paul Calderone Nov 28 '11 at 15:43
  • putting this infront of HTTP has huger infrastructure cost for me. – sheki Nov 28 '11 at 16:15
  • I don't really understand that. Yet... – Jean-Paul Calderone Nov 28 '11 at 17:44
  • Spawning a separate discussion. I need to provide a few API's more likely RPC's. What are my best bets for Python Based solutions/protocols. Here I am trying to write my own protocol. I could have used HTTP+JSON or Thrift. Any thing much simpler I am missing? – sheki Nov 29 '11 at 04:45
  • Thought about this, spoke to a few people, Moving this service over HTTP, Trying to make it restful. – sheki Nov 30 '11 at 17:44

1 Answers1

1

The transport.write call will send the data to the client. If the client is poorly written, it may lose it because the connection closes immediately after the data is sent. There are many other possible ways the client could fail, too, but there's no way to know what's actually happening since the client code isn't part of the question.

Jean-Paul Calderone
  • 47,755
  • 6
  • 94
  • 122
  • Thanks for pointing out. It was the client which was wrongly written. – sheki Nov 29 '11 at 05:42
  • Any idea's on how I can do the above thing correctly. I was inspired by [Memcahce Protocol](http://code.sixapart.com/svn/memcached/trunk/server/doc/protocol.txt) to write my own. It is similar in nature. But I think I am reinventing the wheels => what I have written is similar to what is generated by Apache Thrift. – sheki Nov 29 '11 at 05:45