I need to write backend for a flash game. The game it self is not complicated. The game itself is a small session(around 2 minutes long) but there are many sessions active at a time. What I though of is making a gateway server which accepts connections and multiple servers that host game sessions. Gateway will tell the game server to create new game session and will forward all messages to it's message queue. Game server will process it and reply back to gateway, which in turn will send response back to the client. I want to do this using mono and run on linux as daemons. Can you give opinions about how to make this architecture better?
UPD: The game is not realtime and avg packets per second from a single game session will be around 5-15. Game session has 2 to 4 players. They all have average size of around 10 to 50 bytes. Udp is possible but will be an overkill, so it will to go with tcp.
Related
i search the "best practice" to create a simple multiplayer browser game. i have choose nodejs for the backend and maybe Phaser for the front. But i have a question about the algorithm.
In each tutorial the server respond after a client event. But a lot of generic article speak about a loop which send world data at regular interval to all client (for example the valve article).
So what is true ? What is the correct procedure ? It depends of the game type ?
For your information i want to do a simple twin stick shooter with a little world where we must survive as long as possible. And i want to do a cooperative game.
Thanks for help.
You need to distinguish between
updates directly affecting your player which are triggered by actions of other players
and updates which are triggered by actions of your player
If you build your app using Node.js, I assume you are going to work with one web socket connect per client.
You can send data over the web socket connection any time in both directions. There is no restriction at all, as long as the amount of data is moderate.
The server actively sending world data in a loop (implemented using setInterval in JavaScript) is definitely a good choice for informing players if they are affected by actions of other players. You can also use the loop to let the server respond to actions of your player.
If you assume the loop always informs the clients in the same order (e.g. client #1, client #2, client #3, client #1,... and so on), you could optimize performance by preferring clients that are active right now, and are doing heavy activity (that is "the server responds after a client event"). Particularly if you have many players in the game, this could improve user experience.
I am trying to build a realtime multiplayer game with Node / SocketIO on Heroku and am not sure how to handle multiple dynos with regards to sharing SocketIO connection data.
For example:
I have 2 Heroku dynos, each running Node + SocketIO
Player A hosts a game, and dyno 1 handles that connection
Player B attempts to joins the same game, but due to the Heroku router, dyno 2 ends up handling that connection.
Actions in the game need to happen in real time, so when Player A performs an action Player B needs to immediately see the results of that action.
In a single-dyno environment, this would be relatively simple. When Player A performs an action, it simply gets emitted to player B. How would this work when there are multiple dynos?
Since you aren't able to select (or know) which Heroku dyno you're connecting to (web.1, web.2, or web.n), you will need to find another way to communicate changes in the game across many dynos.
One way to do this would be to additionally use a distributed messaging service for communicating changes in the game. Using a distributed publush-subscribe architecture Player A can send actions in the game to dyno 1, which then puts them on a queue.
Dyno 2 can then subscribe to the game's queue when Player B joins the game. Now, Dyno 2 will receive actions from the game and then be able to send them over the socket to Player B.
While this approach isn't going to be as low of latency as a single high-performance server, something like it might be necessary if you want to get the benefits of scaling and redundancy.
On Heroku, you might consider using Redis for this purpose, since Heroku provides a hosted version and it performs well for low-latency applications.
I'm currently creating a very simple Pong game in Java that is supposed to work over a network. I based the network design off a previous chat client-task I made earlier which consists of a server and a client. The clients connected to the server have separate threads waiting for them to send information to the server (clients are limited to 2 in the pong game obviously)
The way I designed the pong game is that all game logics are calculated on the server since it's such simple calculations and the data is saved in a PongData object that consists of 4 ints and one point (2 ints for players y-positions, 2 for the score and 1 point for the balls positions), this is then broadcasted to the 2 clients through a ObjectOutputStream and all the clients do is display it on the screen. Whenever they press a button on the client that is broadcasted through a DataOutputStream to the server.
When I run the game locally with a server and 2 clients it works perfectly but as soon as I run one of the clients on a separate computer it laggs very badly basically making the game unplayable. I'm unsure what the best practice to design games like these are, I've looked around stackoverflow and the internet and sending objects through UDP seems fairly complicated and most of all very unsafe but I'm not sure how to do it better through TCP without getting such a heavy lag.
Some additional information I can give is that the game loop thread carries out all the calculations, broadcasts the information and then sleeps for 10 ms before repeating it again which gives the game a good speed (locally at least).
Flush your streams, and call Socket.setTcpNoDelay(true) when creating the socket.
I have a socket game server that runs everything on one single process; the problem is when i want to scale out my app.
Since it is a card game and when there is an event on a table, i can easily reach all the players that are in the same room because i have direct access to their socket connection.
if i want another server (or many depending on the load) it is another complete different process and i need to be able to have for instance 1 room, where players from server 1 can play against players from server 2, and in case server 1 fails, the connections can be taken from server 2 and keep them playing without interruptions.
What would be the architecture for this?
Some hosting providers support both websockets and horizontal scaling. This will allow your users to establish a websocket connection with a node. However, you may need an event from that user to broadcast to other users connected to other notes.
You may want to consider something like RabbitMQ. By using a fanout or topic exchange you can broadcast the event to a set of listeners. The listeners will be the various nodes in your cluster that are maintaining the websocket connections.
I am writing a multiplayer real time game for the browser with the server as a master instance and the clients as input devices and slaves to show the graphics.
I have to send out changes in the game world very often and very fast and it doesn't matter if some of the data sometimes gets lost on the way because a couple of milliseconds later there will be the next update anyway.
Right now I am using Socket.io to talk between the server and the clients but this uses TCP which makes the update come in unnecessary late sometimes.
I know that there is WebRTC with data channels where I would be able to send my updates through wit UDP which would be very awesome and exactly what I want. And it even seems to be implemented in Firefox and Chrome already https://stackoverflow.com/a/12864512/63779
What I now need is some Node library which would allow me to use data channels to send my data (for now just JSON strings) with help of UDP to the clients which are browsers. On the browser I would be able to use webkitRTCPeerConnection() but I have no idea how to start something like that on the Node server. Any suggestions? If there is no Node module for that, would it be possible to write something in some other language and just send the data via Unix domain sockets or something?