EEVblog Electronics Community Forum

Products => Computers => Programming => Topic started by: DiTBho on October 14, 2022, 12:23:20 am

Title: web, the server updates the client on event: how?
Post by: DiTBho on October 14, 2022, 12:23:20 am
Usually the web server serves a page at the client's request.
I need the server to update the client in case of an event.

how?  :-//
Title: Re: web, the server updates the client on event: how?
Post by: sleemanj on October 14, 2022, 12:27:01 am
Usually the web server serves a page at the client's request.

The simplest way is to poll for updates.

But you can also look to Push notifications, or Websockets.
Title: Re: web, the server updates the client on event: how?
Post by: Nominal Animal on October 14, 2022, 02:46:46 am
I'd recommend Websockets (https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API).  The idea is that the page contains JavaScript that connects to the server using Websockets, and assigns a function to handle the MessageEvents for that socket.  That way, whenever the server sends something, that Javascript handler gets called.

See the link for further info, guides, and so on.