简体   繁体   中英

Notifications in Node.js

I'm trying to achieve a notification system using NodeJS. Everything is going right: connecting to server, connecting to database, querying the database. Since I have just couple of hours working on NodeJS, I don't have the image clear how the notifications concretely happen. Googeling the issue didn't come actually with great things.
When someone posts a comment, the comment's inserted to the database, that should fire an event to notify his friends (in Friend table) that he posted a comment? Any type of help will be appreciated.
I'm using PHP and MySQL with "mysql" Node module.

Googleing "node.js notifications" I got this http://www.gianlucaguarini.com/blog/?p=272 or this http://gonzalo123.wordpress.com/2011/03/14/real-time-notifications-with-php/ . It uses socket.io as Amberlamps suggests.

In the end you will want to have all of your users (their webbrowsers) run some javascript that opens a websocket (or otherwise, check out Socket.IO) to your node.js server. That connection stays open as long as they stay on the page. Once you want to send them a notification the node.js server does that through this connection. Your PHP script can trigger the node.js server through various ways, but a http request to localhost is probably the easiest and most realtime.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM