<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.28.1">
</HEAD>
<BODY>
>From what I learned in other posts, the dataReceived(self, data): in the Echo server<BR>
will get called with out-of-order data/bytes from the client. Of course, I could be misinformed,<BR>
but what I understood before was that in this type of Protocol, I would have to re-order<BR>
and re-assemble the bytes. And I'm trying to avoid that, since of course, TCP already does it.<BR>
<BR>
But like I said, I could have been misinformed because it seems pretty basic to write 1,2,3<BR>
to a server and have it received 1,2,3, guaranteed.<BR>
<BR>
On Wed, 2010-02-10 at 14:08 -0500, Mark Bailey wrote:<BR>
<BLOCKQUOTE TYPE=CITE>
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>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
On Wed, Feb 10, 2010 at 1:54 PM, Darren Govoni <<A HREF="mailto:darren@ontrenet.com">darren@ontrenet.com</A>> wrote:
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
<BLOCKQUOTE>
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">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>
On Wed, Feb 10, 2010 at 12:22 PM, Darren Govoni <<A HREF="mailto:darren@ontrenet.com">darren@ontrenet.com</A>> wrote:<BR>
<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> <BR>
<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">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</A><BR>
<BR>
</BLOCKQUOTE>
<BR>
<PRE>
_______________________________________________
Twisted-Python mailing list
<A HREF="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</A>
<A HREF="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</A>
</PRE>
</BLOCKQUOTE>
<BR>
<BR>
</BLOCKQUOTE>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
<BLOCKQUOTE>
<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">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">Twisted-Python@twistedmatrix.com</A>
<A HREF="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</A>
</PRE>
</BLOCKQUOTE>
<BR>
</BODY>
</HTML>