Server Messages are not broadcasting to all clients #43

Open
opened 2017-03-27 19:46:23 +00:00 by sathishsanthosam · 0 comments
sathishsanthosam commented 2017-03-27 19:46:23 +00:00 (Migrated from github.com)

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.

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.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: sitegui/nodejs-websocket#43
No description provided.