I want to make a 2 player pong game that uses websockets and node.js server. socket.io is used on both client and server. So far, my only experience is creating a chat application.
This is my first attempt at a multiplayer game so I'm not so familiar with network gaming. Should the server keep track of:
pressHoldStartPosition
and pressHoldStopPosition
? I guess this is easy if I only allow pressing but not holding down.My thoughts:
For web games, generally you'd use something like WebSockets. That's still not ideal, but way better than HTTP.
WebSockets are used for real-time communication between the browser and a server. These communications are bi-directional. Therefore it fits low latency applications such as chat, real-time multiplayer gaming, in-app notifications.
The League Client runs a WebSocket for an event bus which anything using the client may connect to. Developers may also connect to this socket over wss. LeagueConnect provides a function to retrieve a WebSocket connection.
For now, I think there are plenty of applications already using Websocket. And there are many frameworks developed for Websockets in almost all the programming languages. They are very matured as well. Only caveat developers may think of Websocket is that, the fact that it's not HTTP.
You are going to find books, upon books, about gaming networking.
In a brief description, here is what I find an interesting implementation: The server and the client calculate the physics of the game. The server will be a master, and have a correct state of all the entities, while the client will attempt to "predict" the state of the entities and keep a smooth animation. The client will get updated the correct state of entities from server periodically. In some games you might see entities suddenly teleport, and that is because client predicted position does not match the server actual position.
An entity state, such as the ball, or the players, usually contains information such as the position, velocity, button state (key down/key up).
Besides that, it is letting your imagination go wild and testing for the best solution and seeing what works. There are a lot to take into consideration, such as player latency and bandwidth.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With