file transfer send buffer
hey, im using CAsyncSocket class for a file transfer.. its an easy client to server TCP transfer but the problem is how many bytes should i read from the file and send to one Send() function call, i am using a while() until i get a block "error" from the Send() function, i noticed its not so fast if i read and send 1 KB of file data to somebody that pings 200+ to me but if i increase the buffer to like 200 KB it works pretty fast.. how does the http server work? or the ftp server? they always work fast when downloading from any server, how do they know how many bytes of data to send?
and im also facing another problem.. i added a progress bar to show how many bytes have been sent but the thing is the CAsyncSocket doesn't have a SendComplete() event or something like that.. or am i missing something?
the OnSend() event fires only when the Send() function is available for usage again..
thanks
[930 byte] By [
eXistenZ] at [2007-11-20 11:15:12]

# 1 Re: file transfer send buffer
Here's an article that uses CSocket in a separate thread: "Network Transfer Of Files Using MFC's CSocket Class" at http://www.codeproject.com/internet/SocketFileTransfer.asp
Since you obviously understand the difference, you should be able to adapt the code to single threaded CAsyncSocket usage.
Mike
# 2 Re: file transfer send buffer
thanks.. that program works in the same way my program does except that the send buffer is 4096 bytes instead of 1024 bytes i used but i tried that one too, anyway i did a lot of tests and it is not faster than my program at all, its very slow.. i tried the BPFTP Server program and it went as fast as it could (a lot faster than my program or the one you linked me to) so.. all im trying to figure out is how does the BPFTP Server program (for example).. works it must adjust its send buffer automatically or something.. i just can't understand..
# 3 Re: file transfer send buffer
The issue might be related to so-called "round trip time" or RTT. Ping time is usually irrelevant.
Search here for RTT and the SO_SNDBUF option. Try increasing the send buffer to 16K or 32K (the default size is usually around 8K) and see if that improves transfer speed.
Mike
# 4 Re: file transfer send buffer
i can make it fast by just using the Send() function with 500 KB of byte data everytime i call it, it seems to increase the SO_SNDBUF automatically to 500 KB, but then again there can be people who can upload or download with a lot more than that so even if i set the buffer to 500 KB now.. there can be people who will still find it slow because their speed is more than that, i don't think the ftp server uses a 20 MB buffer, and another big problem with these big buffers is that i dont get any progress at all in my program because there is no SendProgress() event or something like that, i could add an option so that you could select your own buffer depending on your connection speed but i still can't find a way to solve the progress problem, i can't think of any way to get any progress in a file transfer when sending, the receiving side however doesnt have any problem with the progress because the OnReceive() event is fired many times, any ideas?
thanks
# 5 Re: file transfer send buffer
There's a progress bar on the sending side in the link I gave you. It uses a registered window message called UWM_FILESENDEVENT (for "file send event").
Mike
# 6 Re: file transfer send buffer
thanks but i already have that kind of "progress" in my application which i cannot call a progress because it will only show you the amount of data that left the pc successfully and not the amount of data actually received by the receiver, i asked about this because i remember that the mswinsck.ocx activex winsock control has a ProgressSend() event so i thought that the CAsyncSocket must have one too, anyway i thought of a way to get a real progress by making the receiver send the amount of data it receives everytime to the server and then when the server receives this it will update the progress bar and everything else but im not sure how good this will actually be, or is there another better way to get a real progress when sending?
# 7 Re: file transfer send buffer
This will probably slow your transfer down, since it burdens the transfer with an intimate handshake between sender and recipient. The fastest transfers occurr when the sender sends continuously, without waiting or looking for any response (such as "I got xx bytes so far") from the recipient.
Mike
# 8 Re: file transfer send buffer
no you got it wrong :P the sender still sends continuously, the receiver sends that stuff only for the progress bar update so its still as fast as before only now it shows the progress correctly.. atleast i tested it a bit and seems to work pretty good, i can't think of another way..