Websocket Javascript - multiple simultaneous connections

Asked

Viewed 28 times

0

Personal talk, I have a function where I make a connection with a websoket, I can connect and everything, only I’m wanting to open 3 connections from 3 different users, I can open these connections so when I send a message from a user To it ends up sending by the user’s connection B and so on, I’d like to know if there’s any way I can make a check of which connection I want this request sent

function openWebSocket(login, mensagem){
    var ws = new WebSocket('ws://asdff.com/websocket');    

    ws.onopen=function(evt) {
        ws.send(JSON.stringify({"ms": login,"name": "login"}));
    };    

    ws.onmessage = function(msg) {

        var data = JSON.parse(msg.data);

        if (data == "user_true") {
            ws.send(JSON.stringify({"ms": mensagem, "name": "info"}));
        } 
    }
}
No answers

Browser other questions tagged

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