Socket.io failed: WebSocket is closed before the connection is established

后端 未结 1 1938
夕颜
夕颜 2021-02-08 23:05

The Issue

My Twitter streaming app using Socket.io works okay when visiting the site with the IP address and port, but live streaming throws an error, when using the d

相关标签:
1条回答
  • 2021-02-08 23:35

    Found the solution, and it was in fact simple! Posting the answer here, to help others facing a similar issue, because I was totally stuck on this for 2 days!

    My issue was caused by a dependency update.

    Socket.io V 2.0.0 is not backward compatible.

    According to the release notes:

    The new (V 2.0.0) major release brings several performance improvements, but also snuck into the bottom of the release notes was this:

    This release is not backward-compatible, due to:

    • A breaking change related to utf-8 encoding in engine.io-parser (socketio/engine.io-parser#81)
    • an update to make the socket id on the client match the id on the server-side (socketio/socket.io-client#1058)

    Please note that if you are using a self-signed certificate, rejectUnauthorized now defaults to true (socketio/engine.io-client#558).

    Here's the full V2 release notes: https://github.com/socketio/socket.io/releases/tag/2.0.0

    The solution is to use HTTPS

    Make your app https, or sign your own requests, as per documentation. As a quick fix though, I just downgraded back to socket.io V 1.7.0 and it works perfectly

    0 讨论(0)
提交回复
热议问题