Answer the question
In order to leave comments, you need to log in
AJAX or sockets for a card game?
Can't decide what would be better for a card game. The engine will be in PHP without any questions, but how the client will not dare to interact: through ajax or sockets?
AJAX is quite simple for me, but with sockets it is more difficult, but whether to deal with it.
They say sockets work with less load than sending ajax requests for each player action.
For sockets, it is written that demons will still be needed, but I have never worked with them.
"Overload" will be noticeable. Just the same VK seems to use only ajax, judging by the analysis on the dialog page.
Answer the question
In order to leave comments, you need to log in
Fully agree with GavriKos . I will add from myself.
First , if the backend is in PHP, the sockets are red-eyed. And if it's on a node, it's quite nice.
Secondly , I will correct GavriKos: if you have a unidirectional exchange - then AJAX, if the exchange is in the direction of client -> server, or Komet, if vice versa, if bidirectional - then sockets are better, although no one bothers you to do AJAX + Komet. But red-eyed.
Wrote a step by step browser. I tried this and that. There are no significant differences in speed and traffic.
- ajax, if you have, for example, four players, then the player's client must send three requests to the server in order to receive response moves, and then make his own.
- websockets, the client or server sent a message and does not know whether it was received or not, does not know which of its almost simultaneous messages will be received earlier and whether it will be received at all. The server received a move message but not in the queue, what should the server do with this move? As a result, in a turn-based game, in order to maintain a consistent state on clients and the server, one has to introduce synchronization mechanisms, practically add to the request-response model originally implemented in ajax over the websocket transport, and the state constantly gets lost and floats and the game crashes and is difficult to debug.
websocket is definitely better for shooting games where speed is important, and a deterministic state is not necessary, well, I missed a couple of steps or shots and that's okay.
I will probably do the step-by-step next game on ajax.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question