Large files and WinSock...

Started by
1 comment, last by Mike 23 years, 4 months ago
When a user joins my game and does not have the custom level that the person hosting the game is using, I want the other person to automatically recieve the custom level. I''m wondering how one should go about sending a large file over the internet using WinSock. I supose I might be able to use WinInet for FTP, but I''d rather not. It seems to me that it would be posible to just load the file into memory and send it with "send". Clearly this is not the best method due to the fact the file might be 10 meg or so in size. I''m thinking the be course of action would be to open the file in binary mode, read in a chunk of the file, and send that chunk to the other computer. Once the other computer has recieved that chunk then the next chunk will get sent. This method leaves me with two questions. Once, how big can a chunk be? Should I get the maximum packet size and just use that? Also, can I just have a loop in the server sending piece after piece or should the server wait for a message from the client saying that the client has recieved the prevoius chunk? Thanks, Mike
Advertisement
anyone?
Well, first off, if you try to send the entire file in one send() call, the send function will regurgitate and only send part of the file. It will report the number of bytes it did send, so you can just advance your pointer into the file and resend from there.

For the read in by chunks concept, there are two schools of thought: one is to send the largest chunk possible at any given time. i.e. keep on sending more information that send can properly handle and use the return value to adjust the number of bytes sent next time. The other school of thought is to send packets so that the network layer packets is the same size as the minimum MTU you might run across. I''m personnally more of the second school of thought.

Also, if you use TCP, the client message facility is built into the protocol. (ACKs are your friend.) Considering that you''re sending a file, which depends on packets arriving reliable as well as in order, TCP seems like the perfect choice.

This topic is closed to new replies.

Advertisement