I want to write a small browser game for my children, such as a quiz with logical questions. I have little experience in creating websites, working with PHP and JS. But I don’t know or don’t understand how a page is changed into one user, depending on the actions of other users. The game will be like a real-time battle between two players. For me, the riddle as without updating and / or clicking on different buttons (links) of the E-mail service page shows me about receiving a new letter? Tell me, please, from where to start digging, what to read? Thank.
- oneI can try to push you right here: socketo.me ... with his initial example of a simple chat on the socketo.me/docs/hello-world websockets ..... and also watch a video on creating a chat on this library youtube.com/ watch? v = RYpSG5d5IPk and download the files github.com/muuknl/phprealtimechat ... to watch them ..... and on the basis of this to do this .. - Alexey Shimansky
|
2 answers
The easiest option is to poll the server with a set period of time for this you can use AJAX . There are more sophisticated options using WebSocket . On the client side, you can also use them here .
- oneAJAX is not the best use. Better use of WebSocket `s - Shnur
- one@Shnur is not the best but simplest. - Shadow33
- I understood that there should be a question-answer and therefore I thought about AJAX myself. But I am confused that the server will be interrogated all the time, for example, 5 seconds. Does this not really load traffic and in general the client itself? - Vitaliy Fesyura
- @VitaliyFesyura yes should not if two players, and you can minimize the data sent to the server. - Naumov
|
JS setInterval function AngularJS $interval On the Front End inside setInterval, do an ajax request on the backend
the server compares the changes to the request and the data from the database
If different then give a response like newData true + data
then change to the village and set the flag newData = false, etc.
Googleworkers use webworker, you can read or type in the search type puller
- Do you even understand what you wrote? - Vitaliy Fesyura
|