Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server Messages are not broadcasting to all clients #43

Open
sathishsanthosam opened this issue Mar 27, 2017 · 0 comments
Open

Server Messages are not broadcasting to all clients #43

sathishsanthosam opened this issue Mar 27, 2017 · 0 comments

Comments

@sathishsanthosam
Copy link

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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant