Connection via socket, only when necessary

Asked

Viewed 52 times

1

I have a web application that needs to update some values frequently, as the changes must be available almost in real time. For this, I run via ajax a refresh.php routine every 15 seconds, which returns updated information. Time that increases if there is no user activity.

I thought about the possibility of creating a service-worker in the browser (since I use it to pwa as well), and in it create a web-socket, and then only when there is an update on the server, create a socket for the ip’s of the users who are logged in (and saved in a db), just to tell the user’s browser that there is an update, then the web-socket triggers the javascript routine that connects to the server and updates.

I do not know if it would be possible to create the socket just to inform that there is an update, because in this case, I do not want to leave the socket open, creating the connection only when there is an update of the information, which in this case, should happen to several users.

Has anyone ever needed or done anything like that, or would have some other idea?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.