I implemented the main website client in JS:
function connectToNotifServer(){
var conn = new WebSocket('ws://localhost:8080');
conn.onopen = function(e) {
alert("Connection established!");
conn.send(JSON.stringify({user_id: sessionStorage.getItem("user_id")}));
};
conn.onmessage = function(e) {
alert(e.data);
};
conn.onclose = function(e) {
alert("Connection closed!");
};
return conn;
}
But I want to use the web socket connection on the page. However, if I just call this method on loading, it bothers me that a new connection will be made every time the page reloads, is this a problem ?. In any case, to make a connection once and use it on different pages and reload the page?
thank
source
share