sending files over network

Started by
7 comments, last by Cipher3D 20 years, 8 months ago
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
I eat heart attacks
Advertisement
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

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

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]

throw table_exception("(? ???)? ? ???");

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.
I eat heart attacks
you don''t have packets with TCP, you send it as a stream.
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
i c...i remember there is a buffer to store outgoing data for TCP/IP, no? Well, what if my file size exceeds that of the buffer?
I eat heart attacks
Then you fill the buffer, wait until it empties, rise and repeat.

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

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

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]
Dave Dak Lozar Loeser
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."--anonymous
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()?

This topic is closed to new replies.

Advertisement