How about:<br><br><br># Copyright (c) 2001-2004 Twisted Matrix Laboratories.<br># See LICENSE for details.<br><br><br>"""<br>An example client. Run simpleserv.py first before running this.<br>"""<br>
<br>from twisted.internet import reactor, protocol<br><br><br># a client protocol<br><br>class EchoClient(protocol.Protocol):<br> """Once connected, send a message, then print the result."""<br>
<br> def connectionMade(self):<br> self.transport.write("hello, world!")<br> <br> def dataReceived(self, data):<br> "As soon as any data is received, write it back."<br> print "Server said:", data<br>
self.transport.loseConnection()<br> <br> def connectionLost(self, reason):<br> print "connection lost"<br><br>class EchoFactory(protocol.ClientFactory):<br> protocol = EchoClient<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><br># this connects the protocol to a server runing on port 8000<br>def main():<br> f = EchoFactory()<br> reactor.connectTCP("localhost", 8000, f)<br> reactor.run()<br><br># this only runs if the module was *not* imported<br>
if __name__ == '__main__':<br> main()<br><br><br>-------------------------<br><br><br># Copyright (c) 2001-2004 Twisted Matrix Laboratories.<br># See LICENSE for details.<br><br><br>from twisted.internet import reactor, protocol<br>
<br><br>class Echo(protocol.Protocol):<br> """This is just about the simplest possible protocol"""<br> <br> def dataReceived(self, data):<br> "As soon as any data is received, write it back."<br>
self.transport.write(data)<br><br><br>def main():<br> """This runs the protocol on port 8000"""<br> factory = protocol.ServerFactory()<br> factory.protocol = Echo<br> reactor.listenTCP(8000,factory)<br>
reactor.run()<br><br># this only runs if the module was *not* imported<br>if __name__ == '__main__':<br> main()<br><br>-----<br><br>Mark<br><br><br><div class="gmail_quote">On Wed, Feb 10, 2010 at 1:54 PM, Darren Govoni <span dir="ltr"><<a href="mailto:darren@ontrenet.com">darren@ontrenet.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>
Hey Mark,<br>
Yeah, that's what I want, but in the 'twisted' way. I can write socket servers, etc. But didn't notice a good example of how to do this in Twisted (sparing me the socket programming), until I found this old message[1] with the classes I think might work.<br>
<br>
[1] <a href="http://twistedmatrix.com/pipermail/twisted-python/2007-July/015738.html" target="_blank">http://twistedmatrix.com/pipermail/twisted-python/2007-July/015738.html</a><br>
<br>
Darren<br>
<br>
On Wed, 2010-02-10 at 13:36 -0500, Mark Bailey wrote:<br>
<blockquote type="CITE">
Hi Darren:<br>
<br>
Why not use TCP? You can send the length of the file at the beginning so you know how many bytes to listen for.<br>
TCP guarantees delivery and ordering.<br>
<br>
Mark<br>
<br>
</blockquote>
<blockquote type="CITE">
On Wed, Feb 10, 2010 at 12:22 PM, Darren Govoni <<a href="mailto:darren@ontrenet.com" target="_blank">darren@ontrenet.com</a>> wrote:
</blockquote>
<blockquote type="CITE">
<blockquote>
Hi,<br>
Is there an existing protocol that can provide the following?<br>
<br>
- Accept stream binary data FROM a client (e.g. very large file transfer)<br>
- Receive data IN ORDER (i.e. stream. not out of order random packets)<br>
<br>
I want to stream FROM a client to the protocol server and have the<br>
server process the stream bytes incrementally so it doesn't have <br>
to store or write the entire data stream (too large).<br>
<br>
I looked at FileTransferServer and Client, but I'm not sure it provides<br>
what I need. <br>
<br>
Any tips appreciated!<br>
<font color="#888888">Darren</font>
</blockquote>
</blockquote>
<blockquote type="CITE">
<blockquote>
<br>
_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com" target="_blank">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
<br>
</blockquote>
</blockquote>
<blockquote type="CITE">
<br>
<pre>_______________________________________________
Twisted-Python mailing list
<a href="mailto:Twisted-Python@twistedmatrix.com" target="_blank">Twisted-Python@twistedmatrix.com</a>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a>
</pre>
</blockquote>
<br>
</div>
<br>_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
<br></blockquote></div><br>