On Tue, 26 Apr 2005 16:30:36 -0700, sir shz firstname.lastname@example.org 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?
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.