Espruino - 使用域名地址ex:ws://someapp.herokuapp.com连接到websocket服务器

时间:2016-11-09 12:46:34

标签: node.js websocket esp8266

我已经使用IP地址和端口

成功连接到websocket服务器
function initsocket(){
  console.log('initsocket');
  var host = "120.188.xxx.xxx"; //its vps address
  var WebSocket = require("ws");
      var ws = new WebSocket(host,{
        path: '/',
        port: 5000, // default is 80
        protocol : "echo-protocol", // websocket protocol name (default is none)
        protocolVersion: 13, // websocket protocol version, default is 13
        origin: 'Espruino',
        keepAlive: 60
      });

  ws.on('open', function() {
    console.log("Connected to server");
  });

  ws.on('message', function(msg) {
    console.log("MSG: " + msg);
  });

}

* STuCK HERE *

但在使用

等域名时仍然卡住(无响应)
var WebSocket = require('ws');
var ws = new WebSocket('ws://ininodeku.herokuapp.com/');
ws.on('open', function() {
    console.log('opened');
});
ws.on('message', function(message) {
    console.log('received: %s', message);
});

但是当使用本机Node.js而不是espruino

时仍然有效

0 个答案:

没有答案