[Twisted-Python] TCP client that can connect to a server at periodic intervals
Gaspard, Bradley S
BRADLEY.S.GASPARD at saic.com
Mon Mar 5 12:58:50 EST 2007
I am trying to write a TCP client that at regular intervals connects to a server makes a request and then closes the connection. Below is the code I've been playing with. I've seen an example of LoopingCall used for periodically sending UPD packets but am not sure how it would apply here because it would seem I need to periodically create new Protocol instances in the ClientFactory class. I've looked for examples and through the documentation but have come up empty. Any pointers would be greatly appreceiated.
print "connectionMade called"
def dataReceived(self, data):
print "Received: ", repr(data)
protocol = AnnouncementFetcher
def __init__(self, share):
self.share = share
def buildProtocol(self, addr):
p = AnnouncementFetcher()
p.factory = self
def clientConnectionLost(self, connector, reason):
print 'Lost connection, Reason:', reason
reactor.callLater(5, self.buildProtocol, 'localhost')
def clientConnectionFailed(self, connector, reason):
print 'Connection failed. Reason:', reason
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Twisted-Python