i am making *something like* downloading manager
and i want to give option to the user to set the Max Speed/sec ( i.e. limit the bandwidth of the program )


any idea about how to make this with non-blocking socket ??
Posted on 2003-08-05 19:23:50 by Sa6ry
Step#1 - write your asynch socket code (single, multisocket, who cares)
Step#2 - introduce a TIMER, and also some COUNTERS which keep track of the total #bytes sent and received. Now you write a code snippet which monitors the counter(s), and divides them by the timer's value (time taken). You are now measuring bytes over time - you have up and down RATE METERS.
Step#3 - make the socket code monitor its rate, and simply idle if the maximum rate is being exceeded.

I'm not really very good at explaining myself, but you should probably just use a WM_TIMER type of timer for your first attempt. See Iczelion's http downloader, it contains a rugged little downrate meter which should get you thinking in the right direction. Bottom line is, you can't regulate the transfer rate if you can't measure it !!!

Hope that helps.
Posted on 2003-08-06 00:17:54 by Homer
thanks alot for your replay ..

my qe. is how to make the socket idle ??

i mean for example when u download a file using HTTP protocol , u send the request and all the file data is sent back to you , how can i make this process idle ..

one solution is to close the socket .. but i don't think this is the right way.

Sa6y
Posted on 2003-08-06 06:56:59 by Sa6ry
If your model uses blocking sockets, put the socket code in its own thread, and use WSAWaitForSingleEvent or associated ws2 function.
If nonblocking, your socket is idling all the time, and winsock only tosses you an FD message when something happens on the socket.
Your notion of sending, then expecting something back, sounds like you are using simple blocking model. I'd actually go with the asynch model (WSASelect) rather than use blocking calls - what if you don't get a reply?
Posted on 2003-08-08 10:29:22 by Homer