Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How Do I Broadcast Json To Users via Node JS server?

How Do I Broadcast Json To Users via Node JS server?

Problem

Goal: After user saves data to my mysql DB, a Json teaser of the newly saved content is broadcasted to all users.

What are some quick and dirty solutions to achieve this? I am working with php/mysql. Got a taste of Socket.io, and a node.js server listening on the side....

Any good links would be greatly appreciated.

Background-------- After many years of working with php, I have decided to jump onto the NodeJS Bandwagon- and have no clue to do anything other than the vanilla "Hello World".... This is my starting point. Thanks again!!

Problem courtesy of: FredTheWebGuy

Solution

If you would like to broadcast to all users including yourself, then you should use:

io.sockets.emit('global', {data: 'this will be received by everyone'}); 

If you would like to broadcast to all users without yourself being notified, then you should use:

socket.broadcast.emit('Hello everyone!');

Hope this helps!

Solution courtesy of: Mohamed Mansour

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

How Do I Broadcast Json To Users via Node JS server?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×