I need to run a script that updates the user's browser once every second. My need is a one way communication from the server to the client.
To do that, I implemented server-sent events polling from my server to the user's client.
The problem is that the user is allow to open multiple connection to the server "by opening multiple browser tabs" witch is a problem as it adds an overhead on the server.
I would like to limit the connection that is coming from a single user to 1. Meaning a single connection to the server across all their tabs. One connection between a client and the server even if the user have 10 browser tabs open.
This is my server-sent event implementation
var evtSource = new EventSource('getMyMessages.php');
evtSource.addEventListener("getMessagingQueue", function(e) {
console.log(e);
var data = JSON.parse(e.data);
processServerData(data);
}, false);
evtSource.onerror = function(e) {
evtSource.close();
};
Is there a way to make this method of communication persistent?