原生nodejs使用websocket

  1. 安装:
    npm  install  ws
  2. 服务端(nodejs):
    var WebSocketServer = require('ws').Server,
    wss = new WebSocketServer({ port: 8080 });
    wss.on('connection', function (ws) {
    console.log('client connected');
    ws.on('message', function (message) {
        console.log(message);
    });
    });
  3. 客户端:
  4. 测试:
    原生nodejs使用websocket
    原生nodejs使用websocket

当前名称:原生nodejs使用websocket
当前URL:http://csdahua.cn/article/jdijgj.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流