如何制作纯Node.js Websocket客户端?

时间:2018-12-03 20:21:48

标签: javascript node.js websocket

假设基于TCP的Web套接字已经创建了一个简单的TCP客户端,但是我无法从 echo.websocket.org 获得任何响应。我在做什么错了?

const connectionData: any = {
  protocol: 'ws:',
  host: 'echo.websocket.org',
  port: '80'
}
var client = new net.Socket();
client.connect(connectionData, function () {
  console.log('Connected');
  client.write('Reply this.');
});

client.on('data', function (data) {
  console.log('Received: ' + data);
});

client.on('close', function () {
  console.log('Connection closed');
});

0 个答案:

没有答案