title: How to limit read speed from a tcp socket
body: <p>I would like to read some data from server. But I want to limit the receiving speed. What is the best way to do that?</p>
  
  <p>Only solution that comes to my mind is to measure how many bytes I received in a certain period of time, calculate speed and then make a decision whether or not to continue reading from socket or to stop for some time.</p>
  
  <p>But I think that it would lead to the fact that for the first part of certain period of time (in which I measure amount of bytes received) speed would tend to a maximum bandwidth and then drop to zero for the remaining part of the period. But I want it to be stable.</p>