Transfering files via TCP/IP
-
In several of my programs I have been using the CSocketComm class[^] in order to send commands between applications, but what I'm not real clear on is how to transfer files. I'm assuming that I will use a CFile or similar on the client side to read the bytes and transfer to the server, which will re-assemble them into another CFile, but I'm lacking in the specifics such as how many bytes to send at a time etc. Does anyone know of a good tutorial that I can read for some help, or is it as simple as I have stated above. Thanks as always for your help, Dustin
-
In several of my programs I have been using the CSocketComm class[^] in order to send commands between applications, but what I'm not real clear on is how to transfer files. I'm assuming that I will use a CFile or similar on the client side to read the bytes and transfer to the server, which will re-assemble them into another CFile, but I'm lacking in the specifics such as how many bytes to send at a time etc. Does anyone know of a good tutorial that I can read for some help, or is it as simple as I have stated above. Thanks as always for your help, Dustin
Dustin Henry wrote:
I'm assuming that I will use a CFile or similar on the client side to read the bytes and transfer to the server...
I think you'd want to use
CFtpConnection
.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
Dustin Henry wrote:
I'm assuming that I will use a CFile or similar on the client side to read the bytes and transfer to the server...
I think you'd want to use
CFtpConnection
.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
I won't actually be connecting to an FTP server, just another computer running my server application implemented with the CSocketComm class. I'm doing this so that I can retrieve current data about the system the application will be hosted on. So in escence I need to send the file from application to application and then have the server side application save the file to disk. Thanks, Dustin
-
I won't actually be connecting to an FTP server, just another computer running my server application implemented with the CSocketComm class. I'm doing this so that I can retrieve current data about the system the application will be hosted on. So in escence I need to send the file from application to application and then have the server side application save the file to disk. Thanks, Dustin
Dustin Henry wrote:
I won't actually be connecting to an FTP server...
Understood. Sorry 'bout that. :-O
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
In several of my programs I have been using the CSocketComm class[^] in order to send commands between applications, but what I'm not real clear on is how to transfer files. I'm assuming that I will use a CFile or similar on the client side to read the bytes and transfer to the server, which will re-assemble them into another CFile, but I'm lacking in the specifics such as how many bytes to send at a time etc. Does anyone know of a good tutorial that I can read for some help, or is it as simple as I have stated above. Thanks as always for your help, Dustin
It sounds like you have it. Send any size chunks you want. Keep in mind the default socket internal buffer size is 8K so for best performance keep those flushed (recv data as fast as you can :)). A chunk/packet size right around 500 bytes will insure each chunk fits in one TCP packet but the protocol handles larger chunks. Without increasing the socket buffer sizes, 500 - 8K byte packets will work well.
-
It sounds like you have it. Send any size chunks you want. Keep in mind the default socket internal buffer size is 8K so for best performance keep those flushed (recv data as fast as you can :)). A chunk/packet size right around 500 bytes will insure each chunk fits in one TCP packet but the protocol handles larger chunks. Without increasing the socket buffer sizes, 500 - 8K byte packets will work well.
Great! Thanks as always for the advice Mark!
-
Great! Thanks as always for the advice Mark!
If you want to achieve high transfer rates you should consider setting you buffer sizes to at least 32K (e.g. read 32K chunks from a file and use a socket send buffer of 32K). Otherwise bulk data transfer will be very likely slower than 100 kB/sec. Tip: Set the server socket send buffer to the wanted size (
SO_SNDBUF
and possible alsoSO_REUSEADDR
) after you created it, sockets created from the listening socket will then inherit this settings. For further reading see Jon Snader's Effective TCP/IP Programming. /M