微信小程序+node验证SocketTask
服务端:node启的一个监听本地端口的服务
1、创建一个新的文件夹,初始化一个package.json
npm init
内容如下:
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"ws": "^7.5.1"
}
}
2、安装依赖
npm install
3、安装ws
npm install ws
4、新建server.js 文件,内容如下:
let wss = require('ws').Server
wss = new wss({port: 8080})
let clients = []
let connectNum = 0
wss.on('connection', (ws) =&g