Node.js with Socket.io - Long Polling fails and throws “code”:1,“message”:“Session ID unknown” response

前端 未结 5 1592
南笙
南笙 2021-01-04 02:43

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

5条回答
  •  清酒与你
    2021-01-04 03:29

    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. When io.connect() is called, the socket.io library makes a call to the server which looks like

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

      server responds with something like

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

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

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

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

      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.

      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.

提交回复
热议问题