赞
踩
ws模块安装
npm install ws
ws官方uuid模块安装
npm install uuid
uuid官方
//搭建ws服务器 const WebSocket = require('ws'); const WebSocketServer = require('ws').Server; const wss = new WebSocketServer({ port: 8888 }); // 引入uuid模块 const { v1: uuidv1 } = require('uuid'); //有客户端连接时 wss.on('connection', (ws) => { //收到客户端发的消息时 ws.on('message', (message) => { ws.send("给客户端发消息") }) })
nodejs-websocket创建websocket服务器
两种方式的客户端创建基本是相同的,参考上方连接
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。