Grant Edwards wrote: > On 2006-09-15, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > >>On 14 Sep 2006 04:54:48 -0700, "billie" <[EMAIL PROTECTED]> 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. > > Of course this depends crucially on the window size. Since the addition of the window scaling TCP option it's been possible to specify very large windows, which are useful over high-bandwidth high-delay links.
The remote (send) throttling will only start to cut in when the window is full (since the whole point of the sliding window mechanism is to allow continuous transmission in the face of acknowledgment delay). regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list