Server-side events (for dummies :))

I have read the spec and some examples / manuals about events on the server side, but now I fully understand the whole process.

If using ajax, the request-> response loop is easy to understand, here it looks a little more complicated. As described here: http://dsheiko.com/weblog/html5-and-server-sent-events , I don’t understand who / what is generating the events on the server. It is as if someone is holding a script server call and this is generating random numbers.

Moreover, the author says: β€œIn addition, you do not need to apply a loop to the script event source. It will look like repeating an automatic click on a message to a client.”
How does this happen?

Thanks,

+6
source share
1 answer

As far as I understand, the server side of the PHP script periodically sends a message. In the example, the link to the script is in the tag named event-source , and the script is events.php . Message onMessageHandler handled by the onMessageHandler function. The handler is assigned to the <event-source> -tag itself; for the Opera a server-time event, the Webkit a message event is processed. It (a browser with HTML5 support), which takes care of the survey, so in fact it is most similar to the browser implementation of a long survey .

As for your question, I don’t understand who / what generates events on the server: there are no events on the server side, this is just a PHP script called from time to time. In the example, when the script returns a timestamp.

+2
source

Source: https://habr.com/ru/post/912359/


All Articles