带有 Socket.io 的 Node.js - 长轮询失败并抛出“代码":1、“消息":“会话 ID 未知"回复 [英] Node.js with Socket.io - Long Polling fails and throws "code":1,"message":"Session ID unknown" response

查看:25
本文介绍了带有 Socket.io 的 Node.js - 长轮询失败并抛出“代码":1、“消息":“会话 ID 未知"回复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么一个移到 IIS7 服务器的 node.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":"Session ID unknown",我不明白,因为我可以看到 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?

任何澄清将不胜感激!

非常感谢!

推荐答案

对于socket.io v2.0.3(js客户端),当你在客户端使用socket.io时,客户端socket.io会进行一些网络调用,解释如下:

For socket.io v2.0.3 (js client),when you use socket.io on client side the client socket.io makes some network calls as explained:

  1. 调用 io.connect() 时,socket.io 库会调用服务器,如下所示

  1. When io.connect() is called, the socket.io library makes a call to the server which looks like

?EIO=3&transport=polling&t=LqtOnHh,

服务器响应类似

"90:0{"sid":"pcJM_AEZirrJT-DuAAUy","upgrades[],"pingInterval":3600000,"pingTimeout":3600000}2:40"

这里服务器在服务器端生成一个套接字对象并发送它的id返回给客户.

here the server generates a socket object on server side and sends its id back to the client.

在此客户端再次调用服务器之后,类似于

After this client makes another call to the server which is something like

?EIO=3&transport=polling&t=LqtR6Rn&sid=0JFGcEFNdrS-XBZeAAXM

这是客户端对服务器进行的长轮询调用,如果您在这里看到它正在传递它在上面第一次调用中收到的 sessionId,如果调用转到生成该 sessionId 的同一节点,则该节点标识套接字已发出请求并响应的连接.

this is the long poll call that client makes to the server, if you see here it is passing the sessionId which it received in first call above, if the call goes to same node which generated that sessionId, the node identifies the socket connection for which the request has been made and responds.

但在 ELB 之后,调用可能会转到未生成此 sessioId 的其他节点,在这种情况下,该节点将无法识别为其进行调用的 sessionId,因此会以 {"code":1,"message":"会话 ID 未知"}

But behind ELB the call may go to some other node that didn't generate this sessioId, in that case the node will not be able to identify the sessionId for which the call was made and hence responds with {"code":1,"message":"Session ID unknown"}

如果长时间轮询未得到应答或超时,您也会看到此错误.

You will also see this error in case of long polling not getting answered or getting timeout.

这篇关于带有 Socket.io 的 Node.js - 长轮询失败并抛出“代码":1、“消息":“会话 ID 未知"回复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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