我已经使用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
时仍然有效