具有Socket.io的Node.js - Long Polling失败并抛出“code”:1,“message”:“Session ID unknown”响应 [英] Node.js with Socket.io - Long Polling fails and throws "code":1,"message":"Session ID unknown" response

查看:998
本文介绍了具有Socket.io的Node.js - Long Polling失败并抛出“code”:1,“message”:“Session ID unknown”响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我坚持为什么移动到IIS7服务器的nod​​e.js应用程序现在失败了。我知道IIS7不支持Web套接字,但我的理解是,如果Web套接字不可用,socket.io将回退到长轮询。所以现在当用户试图按下通常需要套接字或长轮询的特定按钮时,我得到这样的结果:

I'm stuck on why a node.js app that was moved to an IIS7 server is now failing. I know IIS7 doesn't support web sockets but my understanding was that socket.io would fall back to long polling if web socket isn't available. So now when the user tries to press a specific button which would normally have required the socket or long polling I get something like this:

XHR finished loading: POST "https://localhost:817/socket.io/?EIO=2&transport=polling&t=1433777964357-6&sid=QWsESi0c9ih7WMWKAAAC".
GET https://localhost:817/socket.io/?EIO=2&transport=polling&t=1433777963494-5&sid=QWsESi0c9ih7WMWKAAAC 400 (Bad Request)
XHR finished loading: GET "https://localhost:817/socket.io/?EIO=2&transport=polling&t=1433777963494-5&sid=QWsESi0c9ih7WMWKAAAC".
OPTIONS https://localhost:817/socket.io/?EIO=2&transport=polling&t=1433777965127-7&sid=QWsESi0c9ih7WMWKAAAC 
XMLHttpRequest cannot load https://localhost:817/socket.io/?EIO=2&transport=polling&t=1433777965127-7&sid=QWsESi0c9ih7WMWKAAAC. Invalid HTTP status code 400

当我点击GET或XMLHttpRequest时,我可以看到响应是code:1,message:会话ID未知,我不明白,因为我可以看到SID。当我点击为该选项失败列出的代码时,我看到问题来自Request.prototype.create,即xhr发送:

When I click on the GET or the XMLHttpRequest I can see that the response is "code":1,"message":"Session ID unknown", which I don't understand as I can see the SID. When I click on the code listed for the failure for the option I see that the problem is coming from the Request.prototype.create, namely the xhr send:

xhr.send(this.data);

有谁知道造成这些事情的原因是什么?

Does anyone have any idea what could be causing these things?

任何澄清将不胜感激!

Any clarification would be greatly appreciated!

非常感谢!

推荐答案

在我的项目中,我尝试将 transport 选项添加为 websocket ,并且不再出现错误。

In my project, I tried adding the transport option as a websocket and error no longer appears.

io.connect(url, {
   "transports": ['websocket']
})

如果应用程序浏览器兼容性不是问题,那么支持IE和其他旧浏览器会出现问题,因为它们不支持本机websockets似乎是一个解决方案。

It will be a problem with supporting IE and other old browsers as they don't support native websockets, if the application browser compatibility is not an issue this seems a solution.

这篇关于具有Socket.io的Node.js - Long Polling失败并抛出“code”:1,“message”:“Session ID unknown”响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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