Hi
I have the same issue . I am trying to implement a web chat using websocket and Er-lang. The whole set up of mine worked well . But now a facing an issue like the connection is getting replaced by latest connection. I'm not able to distinguish between the user. I have implemented in node js.
My code is below
This is the server side code
wss.on('connection', function (ws) {
function init(user,pass,loginStatus,id) {
//To initiate the xmpp connection
wsURI = "ws://52.77.212.110:5223/xmpp";
//create a new WebSocket object.
wsss = new webSocket(wsURI, [ 'xmpp' ]);
wsss.onopen = function(evt) {
if(loginStatus===true){
login(user, pass,loginStatus);
}
else{
wsss.close(3000,"Deliberate Connection");
}
};
wsss.onclose = function(evt) {
var code=evt.code;
console.log('connection closed');
if(code!==3000){
if(loginStatus===true){
console.log('connection started');
login(user, pass,loginStatus);
}
}
};
wsss.onmessage = function(evt) {
processResponse(evt.data, user, domain,id);
};
wsss.onerror = function(evt) {
console.log('Error Occured');
console.log(evt);
};
this.wsss = wsss;
//
}
}
The client side code
var url = "ws://127.0.0.1:8087/";
socket = new WebSocket(url);
socket.onopen = function () {
var user=document.getElementById("user").value;
var secretCode=document.getElementById("secret-code").value;
setCookie("username", user, 365);
setCookie("user_id", getRandomInt(0, 10000), 365);
var bool=true;
//To set the username in session
var message = {};
message.user = user.trim();
message.pass = secretCode.trim();
message.id = getCookie("user_id");
message.type = "login";
message.connection=bool;
var msg=JSON.stringify(message);
socket.send(encodeURIComponent(msg));
};
Can you please clarify and create an example to reproduce the issue?
The above code is kinda messy and hard to read.
Thanks.
Closing due to inactivity.
Hi,
I have got solution for it. Thanks for your response.
What is a solution?
What is a solution? Please!!!
Most helpful comment
Hi,
I have got solution for it. Thanks for your response.