I am using the ws library for WebSockets in Node.js and I am trying this example from the sample libraries:
var sys = require("sys"),
ws = require("./ws");
ws.createServer(function (websocket) {
websocket.addListener("connect", function (resource) {
sys.debug("connect: " + resource);
setTimeout(websocket.end, 10 * 1000);
}).addListener("data", function (data) {
sys.debug(data);
websocket.write("Thanks!");
}).addListener("close", function () {
sys.debug("close");
});
}).listen(8080);
All OK. It works, but, for example, starts 3 clients and sends "Hello!". from one will make the server respond only "Thank you!" to the client who sent the message, not to everyone.
How can I broadcast "Thank you!" for all connected clients when someone sends “Hello!”?
Thank!
vhyea source
share