You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to create a websocket from Client side and send messages from server node-js.
When ever i receive a message from client, it brodcast well.
But if i send a message from server to all the clients, it is not brodcasting.
below is my code.
var wsCallback = function(connection) {
connection.nickname = null
connection.on("text", function (str) {
connection.nickname = str
broadcasting(str);
})
connection.on("close", function () {
broadcasting(connection.nickname+" left")
})
};
var server = ws.createServer(wsCallback)
server.listen(8081,'localhost')
function broadcasting(str) {
console.log(server.connections.length);
server.connections.forEach(function (conn) {
conn.sendText(str)
})
}
when i call broadcasting from some other method, it is not broadcasting, it says the no of connection is 0.But if i send a message from one of the clients, then that message is broadcasting.
I don't know, what i'm missing. Looks like a referencing issue.
could you please help me solve this issue.
The text was updated successfully, but these errors were encountered:
I'm trying to create a websocket from Client side and send messages from server node-js.
When ever i receive a message from client, it brodcast well.
But if i send a message from server to all the clients, it is not brodcasting.
below is my code.
var wsCallback = function(connection) {
connection.nickname = null
connection.on("text", function (str) {
connection.nickname = str
broadcasting(str);
})
connection.on("close", function () {
broadcasting(connection.nickname+" left")
})
};
var server = ws.createServer(wsCallback)
server.listen(8081,'localhost')
function broadcasting(str) {
console.log(server.connections.length);
server.connections.forEach(function (conn) {
conn.sendText(str)
})
}
when i call broadcasting from some other method, it is not broadcasting, it says the no of connection is 0.But if i send a message from one of the clients, then that message is broadcasting.
I don't know, what i'm missing. Looks like a referencing issue.
could you please help me solve this issue.
The text was updated successfully, but these errors were encountered: