简体   繁体   English

Node.js中的通知

[英]Notifications in Node.js

I'm trying to achieve a notification system using NodeJS. 我正在尝试使用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. 由于我只有几个小时在NodeJS上工作,因此我不清楚该通知如何具体发生。 Googeling the issue didn't come actually with great things. Googeling问题实际上并没有伟大的事情。
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? 当某人发布评论时,该评论已插入数据库中,这将引发一个事件以通知他的朋友(在Friend表中)他发表了评论? Any type of help will be appreciated. 任何类型的帮助将不胜感激。
I'm using PHP and MySQL with "mysql" Node module. 我正在将PHP和MySQL与“ mysql”节点模块一起使用。

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/ . Googleing的“ node.js通知”我得到了这个http://www.gianlucaguarini.com/blog/?p=272或这个http://gonzalo123.wordpress.com/2011/03/14/real-time-notifications- with-php / It uses socket.io as Amberlamps suggests. 正如Amberlamps建议的那样,它使用socket.io。

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. 最后,您将希望所有用户(他们的网络浏览器)运行一些JavaScript,这些JavaScript打开一个websocket(否则,请查看Socket.IO)到您的node.js服务器。 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. 一旦您想要向他们发送通知,node.js服务器就会通过此连接进行通知。 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. 您的PHP脚本可以通过多种方式触发node.js服务器,但是对localhost的http请求可能是最简单,最实时的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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