Project Updates

Posted in Uncategorized by walkingTarget on February 2, 2010 No Comments yet

Did a little work this morning on WarGames’ code base and got file transfer via TCP Sockets working. I sent a 2,360,144 byte file locally (I’m still waiting for a friend to test it remotely) and got the same thing on the other end. To summarize the process, the sender sends the file’s size in bytes, then loops through successive file fread()s and socket send()s to send the file. On the other end, the receiver gets the file size as a reference, then socket recv()s and file fwrite()s to output the file to disk. When sender reaches EOF, it’s done. When the reciever gets the number of expected bytes, it is done.

The impact on WarGames is significant since no game can start until every player possesses the game data of every other player’s army. One thing to consider is multi-threading. You might already be running your network in a thread so that other jobs can continue – rendering, events processing, audio, etc. However, because we’re stuck in a while loop as we recv() and send() files, no other networking actions can occur during transfer. The less obtrusive alternative is give file transfer its own thread and allow basic networking functions to continue unobstructed. This isn’t to say that you should make a thread for each file, however. For each client I would build a file manifest and spawn a thread that transfers all the files they need. As far as the manifest goes, basically they send what they’ve got, the server checks it and starts sending them what they need. The manifest would contain file names, sizes and a checksum to ensure consistency. This also effectively leads to the integration of a progress bar that users can watch as they download.

I’ve also made some bug fixes to the website that I recently discovered. If I actually had any visitors, they would have discovered them first. I’ve also upgraded the server with the dying (yet still more reliable than its predecessor) PSU from my desktop computer. Powering up on the first press of the button is fantastic. =)