Limitate speed of a socket-based data transferring

Grant Edwards grante at visi.com
Fri Sep 15 12:33:56 EDT 2006


On 2006-09-15, Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
> On 14 Sep 2006 04:54:48 -0700, "billie" <gnewsg at gmail.com> declaimed the
> following in comp.lang.python:
>
>> Hi all. I'm writing a TCP-based application that I will use to trasfer
>> binary files through the network. This piece of code represents how do
>> I get a file from a remote peer and save it on my local hard drive:
>> 
> 	<code snipped>
>> 
>> I would like to know how could be possible to limit the file transfer
>> speed (for example: don't write more than 50 Kb/sec).
>> Some ideas?
>> 
> 	I'm not sure you /can/ limit the /receive/ speed.

Sure you can.  Just read data from the socket at the max speed
you want to receive.  The receive buffer for that socket will
fill up and the TCP window will start close up and throttle the
sender.

> The sender will send at whatever rate they are capable of, so
> packets may just become backlogged on your receiving socket

When that happens, the sending end of the socket will throttle
down to match the rate at which data is being read from the
socket.

> waiting for you to read them if you add some sort of delay to
> your reading loop.

-- 
Grant Edwards                   grante             Yow!  .. the HIGHWAY is
                                  at               made out of LIME JELLO and
                               visi.com            my HONDA is a barbequed
                                                   OYSTER! Yum!



More information about the Python-list mailing list