<html><body><br />On 05:58 pm, bradley.s.gaspard@saic.com wrote:<br />><br />>I am trying to write a TCP client that at regular intervals connects to a server makes a request and then closes the connection.<br /><br />Your code has a fatal problem.  Nowhere are you actually creating a client connection, you're just creating protocol objects and not hooking them up to anything!  I've whipped up a quick periodic ping/pong client/server pair for you here, which should provide a useful starting point for you.<br /><br />The key thing is the call to the ClientCreator's 'connectTCP' method, which actually hooks up an instantiated PingSender to a socket.<br /><br />-------- cut<br /><br />from twisted.internet.protocol import Protocol, ClientCreator, Factory<br />from twisted.internet.task import LoopingCall<br />from twisted.internet import reactor<br /><br />class PingResponder(Protocol):<br />    buf = ''<br />    def dataReceived(self, data):<br />        self.buf += data<br />        if self.buf == 'PING':<br />            print 'PONGED!'<br />            self.transport.write('PONG')<br />            self.transport.loseConnection()<br /><br />class PingSender(Protocol):<br />    buf = ''<br />    def connectionMade(self):<br />        self.transport.write("PING")<br />    def dataReceived(self, data):<br />        self.buf += data<br />    def connectionLost(self, reason):<br />        print "PONGED WITH: " +self.buf<br /><br />def client():<br />    cc = ClientCreator(reactor, PingSender)<br />    def dontDelay():<br />        cc.connectTCP('localhost', 4321)<br />    lc = LoopingCall(dontDelay)<br />    lc.start(0.5)<br /><br /><br />def server():<br />    pf = Factory()<br />    pf.protocol = PingResponder<br />    svr = reactor.listenTCP(4321, pf)<br /><br />import sys<br />if sys.argv[1] == 'client':<br />    client()<br />else:<br />    server()<br /><br />reactor.run()<br /></body></html>