【问题标题】:Socket.IO stops working on Google Chrome 43.0.2357.65Socket.IO 在 Google Chrome 43.0.2357.65 上停止工作
【发布时间】:2015-05-22 09:22:44
【问题描述】:

请帮帮我!

在我的网站上更新到最新版本的 Google Chrome (43.0.2357.65) 后,socket.io 停止工作。

它发送的请求太多,每次都创建新的套接字连接。

我的网站谷歌开发者工具截图网络:http://i.stack.imgur.com/TLXGg.png

但 socket.io 网站 http://socket.io/demos/chat/ 上的演示示例工作正常。

socket.io 演示的截图网络://i.stack.imgur.com/QWNW2.png

我在客户端使用这个代码:

 $.getScript('http://localhost:1337/socket.io/socket.io.js', function () {
   var socket = io.connect('http://localhost:1337/?token=ABCDEF');
 });

在其他浏览器中代码运行良好,在更新前的谷歌浏览器中运行良好

Socket.io 版本 1.3.5

在控制台中我有这些调试消息:

engine.io-client:polling-xhr xhr open GET: //it.iksys:1337/socket.io/?token=410235d6a03ead4497fa18037e8da5d73133367d&EIO=3&transport=polling&t=1432302871093-738 +1ms  
socket.io.js?_=1432302864284:3715 engine.io-client:polling-xhr xhr data null +1ms  
socket.io.js?_=1432302864284:3715 engine.io-client:polling polling got data ok +4ms  
socket.io.js?_=1432302864284:3715 engine.io-client:socket socket receive: type "error", data "parser error" +0ms  
socket.io.js?_=1432302864284:3715 engine.io-client:polling polling +1ms  
socket.io.js?_=1432302864284:3715 engine.io-client:polling-xhr xhr poll +1ms  
socket.io.js?_=1432302864284:3715 engine.io-client:polling-xhr xhr open 

【问题讨论】:

  • 不是新连接,是轮询http请求
  • 但是代码停止为我工作。而在 Node.JS 服务器代码中,每个请求都是新的套接字(不同的 socket.id),但必须是一个套接字。
  • 如果我正确理解socket.io,第一个轮询请求接收sid参数(服务器上的socket.id),下一个轮询请求必须在查询中使用这个sid参数创建。但是每个新请求都创建时没有 sid 参数。
  • chrome 控制台出现错误?
  • 控制台没有错误

标签: node.js google-chrome websocket socket.io polling


【解决方案1】:

我找到了只为客户端定义 websocket 传输的解决方案:

NodeJS:

var options = {};
options.transports = ['websocket'];
var socket = io.connect('http://localhost:1337/?token=ABCDEF', options);

角度 4:

 this.socket = io(environment.socketURL, {  upgrade: false, transports: [ 'websocket' ], query: {token: TokenService.token()}});

我想这个版本的谷歌浏览器在 xhr-polling 方面存在一些问题。

【讨论】:

    【解决方案2】:
    // package.json
    {
      "dependencies": {
         "socket.io-client": "2.1.1"
       }
    }
    

    https://github.com/socketio/socket.io-client/issues/1245

    【讨论】:

      猜你喜欢
      • 2015-08-09
      • 2016-05-15
      • 1970-01-01
      • 2016-09-04
      • 2021-11-04
      • 2012-08-18
      • 2014-02-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多