Could someone show me a sample how to flush the socket sending buffer? Thanks a lot.

Jean-Paul Calderone exarkun at divmod.com
Fri Jun 8 22:22:39 EDT 2007


On Fri, 08 Jun 2007 15:36:30 -0700, mike <needpassion at gmail.com> wrote:
>I have called the setsockopt() to set no delay after connecting like
>this way:
>
>        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>        s.connect(('192.168.10.1', 21980))
>        s.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 0)
>        s.send("abc at abc.com\n")
>        s.send("123 at hbc.com\n")
>        ......
>
>but still, the server can only receive the first line, and keep
>waiting for the second line. So, in my mind the second line is still
>in the sending buffer, and not reach the server side.

There is no buffer you can flush.  Also, you forgot to check the return
value of the send method.  It is important.  You might want to look at
the sendall method.  Or you might want to check out Twisted.

Jean-Paul



More information about the Python-list mailing list