views:

198

answers:

1

I'm trying to implement an SSL client in Twisted that simply must connect to a socket and read binary data (specifically, tuples of data). I've gotten the code to a point where it seems to connect and disconnect successfully but no data is ever read from the socket.

class FeedbackHandler(LineReceiver):
  MAX_LENGTH = 1024*1024

  def connectionMade(self):
    log.debug('feedbackHandler connectionMade')

  def rawDataReceived(self, data):
    log.debug('feedbackHandler rawDataReceived %s' % binascii.hexlify(data))
    self.io.write(data)

  def lineReceived(self, data):
    log.debug('feedbackHandler lineReceived %s' % binascii.hexlify(data))
    self.io.write(data)

  def connectionLost(self, reason):
    log.debug('feedbackHandler connectionLost %s' % reason)
    self.deferred.callback(self.io.getValue())
    io.close()

And the code that kicks it off:

factory = self.clientProtocolFactory() # a ClientFactory instance
context = self.getContextFactory(CERT_FILE) # a ClientContextFactory 
reactor.connectSSL(server, port, factory, context)

However when it runs none of the received methods are called, regardless of setRawMode. Is there just nothing to read from the server? connectionMade and connectionLost are called immediately when connecting and terminates with a ConnectionDone error instance.

+2  A: 

Take a look at ssldump or wireshark. Since you're not seeing any data delivered at this level, you should drop down a level to one of these tools. One of them might reveal an SSL negotiation error, or that the server never sends any bytes, or something else that's hard to guess based just on what you've discovered so far. You still might not have the complete answer, but you'll have more pieces of the puzzle.

Jean-Paul Calderone