Networking

warning: Creating default object from empty value in /home/hplus/enchantedage.com/modules/taxonomy/taxonomy.pages.inc on line 33.
Computers talking to computers.
jwatte's picture

Ultimate Sleight of Hand (MMO FPS where everybody wins)

Thinking about how a MMO FPS like Planetside was most fun when you were in a good group, and you were winning, I started thinking about how you could set up a situation where each side can have the impression that it's winning. Playing FPS against NPCs is not as much fun as playing against other people, so it seems like a preposterous idea at the outset.

jwatte's picture

HTTP-GET source code download

If you've ever wanted to read web pages into your C or C++ program, then this code is for you. It's the smallest possible code that will let you read arbitrary web URLs into your own program. It does NOT have any kind of interesting features, and is not coded to be fully standards compliant, but:

  • it comes with source
  • it's very small
  • it works
jwatte's picture

How to re-construct messages on the receiving side

Once you've gotten your message buffer sent to a receiving end (through a file or network interface), you can inflate and re-construct the same data structure using the MsgIn class. Note that the current marshalling code does not compensate for varying byte order across networks, but because all computers you'll be running this code on are little-endian, that probably doesn't matter to you.

jwatte's picture

How to use the generated code: MsgBase.h

The generated code makes use of the pre-defined visitors in MsgBase.h and MsgBase.cpp. It also needs you to generate a source file for your packets file, using perl -MSource Packets.pl. The generated source code is simple:

/*
 * This file was auto-generated on 2008-11-15 11:16:13
 */
 
#include "Packets.h"

jwatte's picture

The output: templates that describe your packets

If you run the perl script, passing in the "Headers" module, it will print the declaration of your data structures to the console output. The included rules file lets you do this automatically as part of a Microsoft Visual Studio project, but for now, try doing it on the command line. If you don't have perl installed, get it either as part of Cygwin, or from ActiveState.

jwatte's picture

The approach: writing a high-level description of each data unit

The idea is to describe your various data structures using a basic high-level language, and then generate the necessary code machinations to go between that description and byte streams automatically. This example uses a custom Perl script, although there are various standardized tools that can do the same thing (such as the ASN.1 standards suite).

jwatte's picture

Marshalling (serializing data) in C++ using auto-generated headers

This package provides simple generation of headers and source for marshalling binary data between C++ structs and byte streams. The nice thing about it is that you can easily extend the system to support generating property sheets, or going to/from XML, or one of a number of other things you want to do to data structures. You do so by just adding new visitor classes, without having to change the data structure code.

jwatte's picture

How to test for duplicate packets

If you're using UDP for your networking, you will typically mark your packets with a "packet ID." That packet ID will be used to detect the case of duplicated UDP packets, and sometimes also dropped packets.

jwatte's picture

Extracting packets from a TCP stream

When you send packets over TCP, you have to precede them with a byte count, because TCP just delivers a stream of bytes, with no particular block size. If you don't delimit your packets somehow, they will run into each other, and you won't be able to tell where one ends and the next one starts.

The XNA Highscores Component (distributed leaderboards, sort-of)

This is a simple game that uses the "HighscoreComponent" to manage a highscore list. It stores the list both locally, and uses Xbox Live! sessions to exchante highscore information with other players who happen to be playing the game at the same time. This way, high scores from people who are not your local players will show up, which is all kinds of cool :-)

This is version 1 of the component, from 2008. It is saved here for historical reasons. You want to get the latest version at http://www.enchantedage.com/highscores which has more features, bug fixes, and is easier to use.

Syndicate content