Network download

I am trying to find the best way to download a file. Currently a game client connects to the game server with the QueuedConnection classes. The client will attempt to join a game but if the map (level) used in that game is not present on the client I it needs to be downloaded.

The manual suggests using HTTPClient but that would mean I’d have to setup a HTTP server (BaseHTTPServer?) on the game server. I would like to keep everything in the current network code.

My idea is to send a series of Datagram strings. However, I haven’t thought this all the way through yet.

Any suggestions, warnings or rants?



What I did was read the raw string from the map file (my maps are just png height maps, but I am positive it will work for any file) sends it as a string, then the client writes to the file. You will need to pack additional data such as what name the file should be written to.

There are some issues to be aware of. If players can join a live game and your map has any dynamic elements those will need to be sent as well, some situations may even require to pause your game code to make sure the new connection syncs up properly.

Size may also be an issue. If it is in the order of megabytes you might need to develop a more dynamic system, especally if players can join mid game. You don’t want to saturate the server network connection sending a player a 10 meg map file.

I’m using the following in a separate thread to download images off the web. Works great for me.

from urllib import urlretrieve

def download(url, toFile):
    urlretrieve(url, toFile)

download("", "c:\\temp\\image.jpg")

I assumed this would be the best/easiest method. My maps are currently binary pickled objects. In the future I might bundle models (egg files) and textures (png or jpg) in a zip or related file.

In my case the game does not start until all players have joined. So this shouldn’t be an issue

This may be an issue. Currently the map files are less than 1MB but if I start bundling models and textures this could increase dramatically. There are a few solutions to this. My current idea is to release asset packs that provide a collection of models and other art assets that will be downloaded separately, from the website for example. The map files will associated with one or more asset packs.

Thanks for your wisdom.

Because of Pirates and Toon Town panda has some nifty file distribution features. You might be able to have the map dynamicly downloaded. Your method would also work very well too and would be much more simple :slight_smile:

Also, once the player download the map “z” then players shouldn’t have to redownload the map again unless map “z” was changed and is now map “a”. You can also make a patch like system that covers smaller changes to the map so users will not have to redownload everything of the map but just the changes.

Panda provides a patch system for that sort of thing.

Each map has an id value which is actually an MD5. I am using this to determine if the map has changed. When a client joins a game the map’s MD5 is sent to the client. The client checks if it has the map with that MD5 if not it requests the map to be downloaded.

I am planning on looking into patching methods. I didn’t know that panda provides one. Could you point me to some documentation or examples?

Also, my maps are pickled objects. I know many people get paranoid about sending pickled objects over a network. I plan on allowing people to run their own game servers which creates an untrusted source. How worried should I be about this? I have also created an XML format for the maps I could use for network transmission.

Thanks for the help,


Check out section AB in the manual, called “Multifiles”. Storing your assets in multifiles is probably a good idea, it has many benefits over conventional loading including the ability to use Panda’s patch system.