[Twisted-Python] flushing the transport

Jp Calderone exarkun at divmod.com
Tue Apr 26 17:50:15 MDT 2005


On Tue, 26 Apr 2005 16:30:36 -0700, sir shz <sir.shz at gmail.com> wrote:
>Hi, I'm just starting to write a simple client, whose protocol inherits from
>basic.LineReceiver:
>
>class MyClientProtocol(basic.LineReceiver):
>     def connectionMade(self):
>          stdout.write("\nconnectionMade\n")
>          self.transport.write("test\r\n")
>          # time.sleep(10)
>
>now if I un-comment the "time.sleep(10)", the server doesn't receive the
>"test\r\n" message until
>10 seconds later, basically after the connectionMade() returns. Is there
>anyway to "flush" the buffer so
>the transport will send the "test\r\n" right away?
>
>Thanks.
>
>Z.
>

  Flushing a buffer is a potentially long-running operation.  What if the buffer was full?  What if the network is congested?  What if the peer has gone away and will never, ever ACK another packet ever again?

  You should rely on protocol-level messages if you need to synchronize things.  You should rely on protocol-level acknowledgements if you need to be certain of delivery.

  All you can rely on transport.write() to do is eventually send the bytes, if it is possible to do so.

  Jp




More information about the Twisted-Python mailing list