DEV Community

Cover image for Presenting a realtime communication framework to build multiplayer games
Srushtika Neelakantam for Ably

Posted on • Updated on • Originally published at ably.com

Presenting a realtime communication framework to build multiplayer games

Hello game developers!

TL;DR - I built a realtime communication framework so game developers can build multiplayer games without needing to worry about the networking side of it and instead focus on their game logic. It is powered by Ably's realtime infrastructure which primarily operates on WebSockets and is built in Node JS and Vanilla JS (use it with any JS framework you like πŸ˜‰). It also implements Node JS worker threads to simulate multiple 'game rooms' (aka dedicated server spooled up on-demand) so different groups of players can simultaneously play the game. You should check it out: https://github.com/Srushtika/multiplayer-games-scalable-networking-framework

Demo application

A few months back I got into the world of building high-frequency (realtime) multiplayer games to get my boss's attention as he's extremely passionate about game development (Challenge: Try to have a tech conversation with Ben Gamble, without game dev coming up!πŸŒšπŸ•Ή).

When I started, I had so many misconceptions about game dev. I underestimated certain aspects and had misconceptions about scalable game architectures. But I've learned so much about game dev since then and have built multiplayer versions of a few classics such as Multiplayer Space Invaders and Multiplayer Flappy birds. I've also written and spoken about game dev quite extensively on various platforms.

Multiplayer space invaders presented at HalfStack online conference, 2020

Multiplayer Flappy Birds, live gameplay on YouTuber Eddie Jaoude's channel

For each such presentation, I made improvements to the games by not only making them more efficient but also having them use the best and latest features of the underlying programming language. For example, I used Node JS worker threads (which was released as a stable version in January 2020) to simulate the idea of having multiple game rooms so different groups of people can play the game simultaneously. This is analogous to spooling up on-demand dedicated servers for each game. Ably's namespace feature made this strategy possible by ensuring none of the rooms had any access to the data from the other.

More games = repeating boilerplate? 🀯πŸ₯΅

While I was continuing to think of more multiplayer game ideas that were cool enough to convince my team to let me work on them during Ably working hours 🌚, I realized some commonalities in all these projects:
All of my multiplayer games so far follow the Client/Server game strategy. Hence, basic networking architecture is exactly the same and has the following aspects:

  • The server maintains the game state and publishes it at high frequency to a channel that all the players are subscribed to. This ensures all players are in-sync.

  • Each player sends their current state (based on user input, etc) on a unique channel meant for that client. The server is subscribed to this and uses this info to maintain the up to date game state mentioned above.

  • The game has multiple game rooms.

  • The host player has options to start and end the game.

  • In general, there's awareness of every player's score, position, alive/dead status, join/ leave updates for the game, etc.

Client/Server architecture with each color representing a realtime channel

Come to think about it, it seems that this is pretty much what most real-time multiplayer games would need. So, I thought building a networking framework would benefit game developers to quickly add the multiplayer functionality to any game. All the more useful when it's built with Ably, as it means you can easily scale it and have access to so many other realtime communication features (like message ordering, availability, guaranteed message delivery, etc) So, here it is!

Multiplayer games scalable networking framework

This framework serves as a starter kit that allows you to add multiplayer functionality (that follows the Client/Server strategy to your game. It provides a communication framework so that your players can communicate with a central server, in realtime, for the entire duration of the gameplay.

Homepage of the demo app that works on this framework

It also allows you to implement a 'game rooms' feature using Node JS worker threads, which is analogous to spooling up dedicated servers on-demand, allowing you to spin up multiple instances of the game, each with a separate group of players. It comes with a skeleton demo app where this game functionality can be simulated. The idea is for game developers to take this framework and add their game logic to make it their own!

Host waiting area of the demo app that works on this framework

You can find the full project with a detailed guide on how to use it on GitHub: https://github.com/Srushtika/multiplayer-games-scalable-networking-framework


If you have any questions/ suggestions, etc. Feel free to shoot an email to devrel@ably.io or reach out to me directly on Twitter, I'll be so glad to talk about this πŸ˜ƒ

If you like it, star it ⭐️ and don't forget to share any multiplayer games you build with this, I'd love to check them out and give a shoutout! πŸ₯‡πŸš€πŸ”₯

Top comments (3)

Collapse
 
andrewbaisden profile image
Andrew Baisden

Cool thats a fun project you made.

Collapse
 
angel17 profile image
Angel Superstore

So useful. Thanks for sharing this information. cash for cars chelsea

Collapse
 
gregwoodsfrontier profile image
Richard Chung

how can I integrate this with phaser ?