<!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.&nbsp; 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>
    &quot;&quot;&quot;<BR>
    An example client. Run simpleserv.py first before running this.<BR>
    &quot;&quot;&quot;<BR>
    <BR>
    from twisted.internet import reactor, protocol<BR>
    <BR>
    <BR>
    # a client protocol<BR>
    <BR>
    class EchoClient(protocol.Protocol):<BR>
    &nbsp;&nbsp;&nbsp; &quot;&quot;&quot;Once connected, send a message, then print the result.&quot;&quot;&quot;<BR>
    &nbsp;&nbsp;&nbsp; <BR>
    &nbsp;&nbsp;&nbsp; def connectionMade(self):<BR>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.transport.write(&quot;hello, world!&quot;)<BR>
    &nbsp;&nbsp;&nbsp; <BR>
    &nbsp;&nbsp;&nbsp; def dataReceived(self, data):<BR>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;As soon as any data is received, write it back.&quot;<BR>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;Server said:&quot;, data<BR>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.transport.loseConnection()<BR>
    &nbsp;&nbsp;&nbsp; <BR>
    &nbsp;&nbsp;&nbsp; def connectionLost(self, reason):<BR>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;connection lost&quot;<BR>
    <BR>
    class EchoFactory(protocol.ClientFactory):<BR>
    &nbsp;&nbsp;&nbsp; protocol = EchoClient<BR>
    <BR>
    &nbsp;&nbsp;&nbsp; def clientConnectionFailed(self, connector, reason):<BR>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;Connection failed - goodbye!&quot;<BR>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reactor.stop()<BR>
    &nbsp;&nbsp;&nbsp; <BR>
    &nbsp;&nbsp;&nbsp; def clientConnectionLost(self, connector, reason):<BR>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;Connection lost - goodbye!&quot;<BR>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reactor.stop()<BR>
    <BR>
    <BR>
    # this connects the protocol to a server runing on port 8000<BR>
    def main():<BR>
    &nbsp;&nbsp;&nbsp; f = EchoFactory()<BR>
    &nbsp;&nbsp;&nbsp; reactor.connectTCP(&quot;localhost&quot;, 8000, f)<BR>
    &nbsp;&nbsp;&nbsp; reactor.run()<BR>
    <BR>
    # this only runs if the module was *not* imported<BR>
    if __name__ == '__main__':<BR>
    &nbsp;&nbsp;&nbsp; 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>
    &nbsp;&nbsp;&nbsp; &quot;&quot;&quot;This is just about the simplest possible protocol&quot;&quot;&quot;<BR>
    &nbsp;&nbsp;&nbsp; <BR>
    &nbsp;&nbsp;&nbsp; def dataReceived(self, data):<BR>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;As soon as any data is received, write it back.&quot;<BR>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.transport.write(data)<BR>
    <BR>
    <BR>
    def main():<BR>
    &nbsp;&nbsp;&nbsp; &quot;&quot;&quot;This runs the protocol on port 8000&quot;&quot;&quot;<BR>
    &nbsp;&nbsp;&nbsp; factory = protocol.ServerFactory()<BR>
    &nbsp;&nbsp;&nbsp; factory.protocol = Echo<BR>
    &nbsp;&nbsp;&nbsp; reactor.listenTCP(8000,factory)<BR>
    &nbsp;&nbsp;&nbsp; reactor.run()<BR>
    <BR>
    # this only runs if the module was *not* imported<BR>
    if __name__ == '__main__':<BR>
    &nbsp;&nbsp;&nbsp; main()<BR>
    <BR>
    -----<BR>
    <BR>
    Mark<BR>
    <BR>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    On Wed, Feb 10, 2010 at 1:54 PM, Darren Govoni &lt;<A HREF="mailto:darren@ontrenet.com">darren@ontrenet.com</A>&gt; wrote:
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BLOCKQUOTE>
        Hey Mark,<BR>
        &nbsp;&nbsp; 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),&nbsp; 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?&nbsp; 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 &lt;<A HREF="mailto:darren@ontrenet.com">darren@ontrenet.com</A>&gt; wrote:<BR>
            <BLOCKQUOTE>
                Hi,<BR>
                &nbsp; 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>