Peter,<br><br>Thanks for the assistance. I think you and David have me on the right path. Just to clarify the protocol looks like this:<br><br>Content-Length: 984<br>Content-Type: text/event-xml<br><br><event><br> <headers><br>
$bunchofinfo ...<br> </headers><br></event><br><br>Where the body (and the content length) start and stop with the <event> ... </event>.<br><br>Here is what I've done so far:<br><br>from twisted.internet import reactor, protocol<br>
from twisted.protocols import basic<br>from re import compile, findall<br><br>bl_p = compile('Content-Length:\s(\d+)')<br><br>class My_Client(basic.LineReceiver):<br> def __init__(self):<br> self.body_length = None<br>
<br> def connectionMade(self):<br> self.transport.write("login \r\n\r\n")<br> self.transport.write("sendevents\r\n\r\n")<br> <br> def lineReceived(self, line):<br> print line<br>
bl_m = bl_p.findall(line)<br> if bl_m:<br> print 'Match:'<br> self.body_length = int(bl_m[0]) - len(line) # this doesn't really work because it doesn't factor in the len of the next line<br>
self.setRawMode()<br><br> def rawDataReceived(self, data):<br> datalen = len(data)<br> if self.body_length > datalen:<br> self.body_length -= datalen<br> print data<br> else:<br>
part = data[:self.body_length]<br> extra = data[self.body_length:]<br> print 'Left Over\n:'<br> print extra<br> self.setLineMode(extra=extra) <br><br> def connectionLost(self, reason):<br>
print "%s" % (reason)<br><br>class My_Factory(protocol.ClientFactory):<br> protocol = My_Client<br><br> def clientConnectionFailed(self, connector, reason):<br> print "Connection failed - goodbye!"<br>
reactor.stop()<br> <br> def clientConnectionLost(self, connector, reason):<br> print "Connection lost - goodbye!"<br> reactor.stop()<br><br>def main():<br> f = FS_Factory()<br> reactor.connectTCP("$IP", $PORT, f)<br>
reactor.run()<br><br># this only runs if the module was *not* imported<br>if __name__ == '__main__':<br> main()<br><br>To me ... this looks somewhat correct ... but it doesn't seem to actually ever use the line received method (note the print statement ...). For instance upon logging in it should respond with a +OK Logged In ... but it never prints that.<br>
<br>And then when it receives an "<event>..." it actually dies with this error:<br><br>[Failure instance: Traceback (failure with no frames): <class 'twisted.internet.error.ConnectionDone'>: Connection was closed cleanly.<br>
]<br>Connection lost - goodbye!<br><br>So I'm a bit lost as to what the impact of adding the rawDataReceived method has done. <br><br>Thanks!<br><br>SDR<br><br><br><br>