A
A
Albert Kazan2017-04-23 11:46:41
Game development
Albert Kazan, 2017-04-23 11:46:41

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

3 answer(s)
D
Dark Hole, 2017-04-23
@abyrkov

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.

U
uvelichitel, 2017-04-23
@uvelichitel

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.

G
GavriKos, 2017-04-23
@GavriKos

If the game needs realtime and reaction speed is important, then sockets. If the reaction speed is not important (a clear deterministic move), then ajax is also possible.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question