我正在尝试使用 NodeJS 实现长轮询技术。
我在服务器上部署了这个基本代码。
http = require('http');
function onRequest(request, response) {
console.log('onRequest reached');
}
http.createServer(onRequest).listen(8080);
console.log('Server has started.');
当请求 localhost:8080 时,会触发 onRequest。当此连接处于活动状态时,我在第二个选项卡中请求同一页面,但不会触发 onRequest。但是,从另一个浏览器请求同一页面会触发 onRequest,而第一个连接仍然是“长轮询”。
浏览器有什么限制吗?这是如何以及为什么会发生的?如何避免这种情况?
顺便提一句。我正在尝试实现长轮询聊天和通知系统。实际上请求应该通过 AJAX 调用进行。