websocket Failed to execute 'send' on 'WebSocket': Still in CONNECTING state解决

websocket 实例化后报错 : Failed to execute ‘send’ on ‘WebSocket’: Still in CONNECTING state
这是因为客户端就会与服务器进行连接。连接还未成功;

解决办法

在websocket open 函数里面 执行send 方法 就可以

  var tsocket = new sgcWebSocket('ws://127.0.0.150:5414');
  tsocket.on('open',function(event){
        tsocket.send('OpenBarScanner')
    });

你可能感兴趣的:(websocket Failed to execute 'send' on 'WebSocket': Still in CONNECTING state解决)