如何使用节点将数据推送到客户端 [英] How to push data to client using node

查看:105
本文介绍了如何使用节点将数据推送到客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用node制作电子邮件客户端.我想在收到任何新电子邮件后立即更新浏览器窗口.我已经在使用mail-listener2在服务器端获取电子邮件了.我想将这些数据推送到客户端.我该怎么办?

I'm using node to make an email client. I want to update the browser window as soon as any new email arrives. I'm already fetching the emails on server side using mail-listener2. I want to push that data to client side. How do i do that?

推荐答案

看看使用 websockets 将数据实时推送到客户端(浏览器).我建议使用 http://socket.io .他们上面有一些非常不错的演示,以展示您将如何做这样的事情.

Look at using websockets to push data in realtime to the client (browser). I would recommend using http://socket.io. They have some really great demos on there to show how you would do something like this.

您的服务器将发送名为message的socket.io消息,其中包含消息详细信息为JSON.您的客户端将监听message事件,并在事件进入时更新用户界面.

Your server would send socket.io messages called message, containing the message details as JSON. Your client would listen for message events and update the UI as they come in.

这篇关于如何使用节点将数据推送到客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆