2

I'm new to Node.js, and I've been playing with the "chat" example provided with the Socket.io install package. Is shows in a few lines of code how you can push some data to several clients (browsers) in a push-fashion (no pulling).

Here is the code on the server side : http://pastie.org/1537175

I get how you can send a message to a client with client.broadcast(msg), but I don't get how you can do it outside of the

io.on('connection', function(client){ ... }

loop

I would like to invoke a client.broadcast(msg) when someone hits a particular url (like '/test.html'), see line #32. The device asking for the '/test.html' is not a typical "ajax-enabled" browser, but a mere text-based browser, so I cannot initialize an asynchronous request with the server. Any idea?

Thank you.

1 Answer 1

1

you can use .broadcast on your io object

case '/test.html':
    io.broadcast('test'); // This is where I would like to invoke a client.broadcast(msg);
    break;
Sign up to request clarification or add additional context in comments.

1 Comment

Thx, i feel so stupid! I ended up using express + faye : stackoverflow.com/questions/4096946/socket-io-with-express

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.