socket.io console报websocket is closed before the connection

IT小君   2021-09-04T08:46:49

原因:

 

连接socket时需要通过IP获取到对应主机的域名来进行连接,此过程会相当耗时
前端有一个超时时间,导致无法在规定时间内收到服务端消息而触发超时操作
 

解决办法

因为ws不会跨域 直接连接 ws服务器地址,以减少域名解析之类的问题

const socket = io("ws://example.com",{
        query: { clientid: userTmp.userID },transports: ["websocket"] 
    });

 

点击广告,支持我们为你提供更好的服务
评论(30)