简体   繁体   English

从不带socket.io的node.js向客户端发送消息

[英]Send message to client from node.js without socket.io

I'd like to be able to send a message to a client from a node.js app, without using something like socket.io. 我希望能够从node.js应用程序向客户端发送消息,而无需使用socket.io之类的东西。 For example, is it possible to send from the client an AJAX request that won't expire? 例如,是否可以从客户端发送永不过期的AJAX请求? Then, where there is data on the server side, I can use the that session to push the message to the client. 然后,在服务器端有数据的地方,我可以使用该会话将消息推送到客户端。 Or may be, someone has better idea? 也许是,有人有更好的主意?

Of course polling from the client is the trivial answer, but I'd like to avoid this. 当然,从客户端进行轮询是不重要的答案,但我想避免这种情况。

Thanks a lot in advance. 非常感谢。

You can use Server-Sent Events . 您可以使用服务器发送的事件 Here's a module that will handle the harder parts for you: https://www.npmjs.com/package/sse 这是一个可以为您处理较难零件的模块: https : //www.npmjs.com/package/sse

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

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