Adventures in Networking part 1

Posted by Astryl on April 5, 2013, 3:04 a.m.

Copied over from my blog here.

For the last two-and-a-half days, give or take, I have been working on writing my own server/client framework for my games; an interesting experiment and potentially useful in the future.

So far, I have a working and decently fast system, that technically allows for 'unlimited' connections; but for sensibilities' sake, I hard capped it to 32.

Here's an overview of what I have so far, and how it works.

The Server

The server is a standalone CLI program. It exists solely as a data exchange and 'meeting post' for clients. All computation occurs on the client side.

I use a simple packet system, (SFML's packets, actually), and insert 'messages'. These messages are read by the server program and the required action is taken.

Some of the messages are as follows:

MESSAGE - A chat message

DISCONNECT - Self explanatory

CLIENT_FRAME - Stores a gm_object. See below.

GET_FRAME - Requests that a frame be sent with the matching ID.

PING - Can be sent to the server, and vice versa. Used to check for a 'heartbeat'.

The Client

In this case, the client is a DLL designed for use within Game Maker. The current behavior allows you to 'save' important variables within an object (Say, the player object), and retrieve them for given player ids.

Under this system, in a game with 8 players, your player will SEND it's "state" after a given number of frames (Both server and client are running on fixed-step, and with a 'clock' variable that syncs the clients to the server and helps with precedence of actions.

The other 7 players will likewise be sending their client states. On the receiving side, each instance of the player objects will 'request' the matching data set from the server (By providing the codes given to them when they are connected).

At the moment, this makes for about 56 bytes + overhead, so around 64 bytes of data per player, per update. I'm not sure how this will measure up in an applied situation, but it works fine on a LAN connection so far (Which is at least one of my goals complete: Some form of networked multiplayer for my games).

The list of things that still need to be done

As I stare at the 'source' for one of my games, and think about 'converting' it to include multiplayer, I tremble. I think I'm going to do this as a from-scratch side project instead of as a conversion. Multiplayer needs to be designed into the game, not hacked into it :P

Anyway, that's all for now. I'm still working out the DLL tutorial thingy I was planning on writing. There are a few pitfalls when dealing with GM, in how it stores variables and passes them to DLLs that I will be covering.

For now, I need to get back to doing something relatively useless. Like playing a game.

Comments