Question
-
Is it possible to communicate events or javascript simply through ajax/xhr?
-
And if so, how asynchronous/synchronous would this be?
Context
- I’m attempting to build a basic pong multiplayer webapp based around javascript/jquery. I thought about how I could synchronize movement between the players on both clients and decided that I wanted to keep it as much client-side as possible. Played around with some ideas, (it was as bad as me thinking about using txt files with 3 boolean values and a user id being called for every single game) but I really couldn’t think of any better way short of using some kind of js backend engine. (which i really do not want to do).
You can use WebSocket (HTML5) for that. Most of the modern browsers support it.
http://slides.html5rocks.com/#web-sockets
More Info: http://www.html5rocks.com/en/tutorials/websockets/basics/
Fun fact: Stackoverflow uses WebSocket too! ws://sockets.ny.stackexchange.com
Example of using WebSocket in multiplayer games: