yodaos-project / ShadowNode

Use Node.js in your end devices(QQ: 796448809)
https://yodaos-project.github.io/ShadowNode/
Other
588 stars 46 forks source link

websocket: handshake failed #559

Open qile222 opened 5 years ago

qile222 commented 5 years ago
var WebSocketClient = require('websocket').client;
var client = new WebSocketClient();

client.on('connectFailed', function(error) {
    console.log('Connect Error: ' + error.toString());
});

client.on('connect', function(connection) {
  console.log('WebSocket Client Connected');
  connection.on('error', function(error) {
    console.log("Connection Error: " + error.toString());
  });
  connection.on('close', function() {
    console.log('echo-protocol Connection Closed');
  });
  connection.on('message', function(message) {
    if (message.type === 'utf8') {
      console.log("Received: '" + message.utf8Data + "'");
    }
  });

  function sendNumber() {
    if (connection.connected) {
      var number = Math.round(Math.random() * 0xFFFFFF);
      connection.sendUTF(number.toString());
      setTimeout(sendNumber, 1000);
    }
  }
  sendNumber();
});

client.connect('wss://echo.websocket.org', 'echo-protocol');

connect error with following message:

Connect Error: Error: handshake failed {"connection":"Upgrade","date":"Thu, 12 Sep 2019 03:54:23 GMT","sec-websocket-accept":"s3pPLMBiTxaQ9kYGzzhZRbK+xOo=","server":"Kaazing Gateway","upgrade":"websocket"}
issue-label-bot[bot] commented 5 years ago

Issue Label Bot is not confident enough to auto-label this issue. See dashboard for more details.