<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7651.59">
<TITLE>TCP client that can connect to a server at periodic intervals</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<BR>

<P><FONT SIZE=2>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.<BR>
<BR>
class AnnouncementFetcher(protocol.Protocol):<BR>
<BR>
&nbsp;&nbsp;&nbsp; def connectionMade(self):<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;connectionMade called&quot;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.transport.write(MSG_INFO_IPC)<BR>
<BR>
&nbsp;&nbsp;&nbsp; def dataReceived(self, data):<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;Received: &quot;, repr(data)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # self.factory.share.saveData(data)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.transport.loseConnection()<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
<BR>
class AnnouncementFetcherFactory(protocol.ClientFactory):<BR>
&nbsp;&nbsp;&nbsp; protocol = AnnouncementFetcher<BR>
<BR>
&nbsp;&nbsp;&nbsp; def __init__(self, share):<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.share = share<BR>
<BR>
&nbsp;&nbsp;&nbsp; def buildProtocol(self, addr):<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print 'Connected.'<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p = AnnouncementFetcher()<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p.factory = self<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return p<BR>
<BR>
&nbsp;&nbsp;&nbsp; def clientConnectionLost(self, connector, reason):<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print 'Lost connection,&nbsp; Reason:', reason<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reactor.callLater(5, self.buildProtocol, 'localhost')<BR>
<BR>
&nbsp;&nbsp;&nbsp; def clientConnectionFailed(self, connector, reason):<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print 'Connection failed. Reason:', reason</FONT>
</P>

</BODY>
</HTML>