S
S
serious9112016-05-13 14:33:23
PHP
serious911, 2016-05-13 14:33:23

Multiplayer for online game (HTML5/JS/AS3)?

Hello.
It is necessary to implement multiplayer for several desktop and mobile online games. Games are developed on HTML5/JavaScript/ActionScript 3. No super complex synchronization and realtime on the server side is needed. Since the games are relatively simple (for example, fool / backgammon / chess / bulldozer), then you need to implement something like game rooms / tables with the number of players from 2 to 10-15 (no more) + text chat.
In each game room, one of the players makes some action / move, and everyone else must wait at this time + there should be a general synchronization (update) between the players so that each player in the room sees how the current active player was like and what happened at that time. It is also necessary to implement control of the entry / exit of players from the rooms.
The main requirements are maximum simplicity, scalability and high loads. I do not want to create another cycle using UDP / sockets in C ++ / Java. At the moment, I see the solution as follows. Basic information about users (logins/passwords/balance/level, etc.) will be stored in a MySQL database + replication to several servers. All information about game rooms will be stored in in-memory storages like Redis (for quick access). Data from clients will come via the HTTP protocol in the form of JSON. NGINX + PHP/Python will be used to process HTTP requests. Clients will update the playing field/room/table by regularly sending API requests to the server (possibly Long Polling). The server will check the state of the game room in Redis and update the state/pass control/turn to the next player.
Please advise how to implement all this more correctly in terms of architecture / optimization of server load and scaling. I understand that there is no completely ready-made solution, so I will be glad to hear any advice / links / frameworks / libraries / other people's experience for writing a server less painfully.
Especially interesting is the experience of developers of multiplayer social and mobile games (not Unity3D).
Priority languages ​​and technologies: HTML5, JS, AS3, MySQL, Redis, Memcached, PHP, Python, Java.
Thank you.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
littleguga, 2016-05-13
@serious911

If you say that some of the clients are already made in html5 / JS, then in general the simplest thing will be to take: socket.io and raise the server to nodejs with the same socket.io only as a server. The data is also in the database + radish cache. Especially nothing more is needed.
+ look towards the ionic framework, it allows you to wrap a web application in a native one on mobile platforms, if games are not loaded with animation, then it is quite a worthy option.
And in the end, it turns out that you need to make 1 client on js + socket.io, just upload it on the web, and wrap it in ionic on mobile phones. And make a server that will create rooms and accept new connections.
PHP is a poor fit as it is quite painful to implement normal socket/long-polling interaction with rooms.
I think it will be useful to see:
Regarding the load:
socket.io benchmark
1 million connections per 15GB RAM
600k connections

A
Alexander Kubintsev, 2016-05-13
@akubintsev

The problem is not so much in the choice of tools, but in the development of an architecture capable of horizontal scaling.
There is no particular difficulty in doing php / python and even perl communication through (web) sockets. The advantage of node.js is perhaps in asynchronous work with storages out of the box, but this does not mean that it will be faster right away.
From myself, I would recommend using PostgreSQL rather than MySQL. More reliable and at least not slower.
The database needs to be sharded right away. At least shards for user-specific information.
Most likely, you will also have to write a proxy for scattering users across different game servers.
In general, for good, you need at least a senior with experience in combat game development.

S
spotifi, 2016-05-13
@spotifi

If we are really talking about large scaling, then look towards the microservice architecture.
SQL doesn't scale well horizontally (by adding servers).
I would consider abandoning MySQL in favor of MongoDB, for example, it can scale horizontally.
I would consider abandoning the database altogether in favor of Tarantool. If there is enough RAM to keep the entire database in it, then it is radically faster.
In our time, this is not cool, and in terms of resources as well. I would consider websocket for new clients and long polling for old ones.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question