Archived

This topic is now archived and is closed to further replies.

Cipher3D

sending files over network

Recommended Posts

I''m creating a multiplayer game, and I want to add functioniality so that if a player connects to a server that has a map that the user doesn''t currently have, the player would download the file (similar to Quake and Counter-Strike). However, how would i do this using UDP? Do i divide up the files or just load the whole file into RAM and send the whole data chunk over the network (i don''t think so.) i suppose i have to go with the first way, but how would i determine how i would divide up the file (because different people have different bandwidth, and i don''t want everybody uploading/downloading at the same rate). thx in advance. Ciph

Share this post


Link to post
Share on other sites
I wouldn''t use UDP, because it''s nonguaranteed (and you need to make sure that the file is EXACTLY the same on both client and server). I guess you could do it if you split it up into chunks and compare checksums for each chunk, bittorrent-stylee.

Instead, I''d recommend using TCP for it.

After that it''s just a question of knowing the filename, and then writing the packet contents to that file as you recieve them....

Superpig
- saving pigs from untimely fates, and when he''s not doing that, runs The Binary Refinery.
Enginuity1 | Enginuity2 | Enginuity3 | Enginuity4

Share this post


Link to post
Share on other sites
I agree with SuperPig. This is the kind of thing TCP was meant for. You could do it with UDP if you want, but its more work and no real gain for this type of thing. Use TCP, theres probably some good code for this type of thing available if you look around for it, although I wouldn''t imagine it would be hard to write yourself.


Ravyne, NYN Interactive Entertainment
[My Site][My School][My Group]

Share this post


Link to post
Share on other sites
yea, thats what i thought, , but how would i determine each packet size? and would you guide me to any google searches? (i couldn''t find anything useful with "sending files over TCP/IP"). thx a l ot.

Share this post


Link to post
Share on other sites
If you are using Winsock2... try using TransmitFile(). Here's the description of TransmitFile():
quote:
MSDN
The TransmitFile function transmits file data over a connected socket handle. This function uses the operating system's cache manager to retrieve the file data, and provides high-performance file data transfer over sockets.
...
Header : Declared in Mswsock.h.
Library : Use Mswsock.lib.




Dave "Dak Lozar" Loeser

-EDIT-
Oh, BTW, this is use on the server side... I think the above descriptions of recieving the file data are still valid - this just simplifies the server side of the code.

[edited by - Dak Lozar on August 13, 2003 1:47:40 PM]

Share this post


Link to post
Share on other sites
On that note above about the OS''s buffer size... is that determined by the amount of free memory available or is it a predefied limit (ex. all XP''s have a buffer size of N bytes)? Also, what is a safe estimate for the most data you should send with one call to send()?

Share this post


Link to post
Share on other sites