socket.io作为客户端

Vit*_*tor 7 node.js socket.io nowjs-sockets

有没有办法将socketio作为客户端运行(不是浏览器,而是nodejs脚本)

我需要将数据从服务器广播到一些客户端(浏览器)和另一台Linux机器(只运行nodejs来获取变量,没有浏览器)

任何想法都是受欢迎的

问候

Tim*_*ple 4

github上有一个项目实现了socket.io客户端。看看这里:

https://github.com/remy/Socket.io-node-client

var socket = new io.Socket('localhost', 8000);

socket.on('connect', function () {
  console.log('yay, connected!');
  socket.send('hi there!');
});

socket.on('message', function (msg) {
  console.log('a new message came in: ' + JSON.stringify(msg));
});

socket.connect();
Run Code Online (Sandbox Code Playgroud)