1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| const WebSocket = require('ws'); const wss = new WebSocket.Server({ port: 7890 });
const clients = new Set(); wss.on('connection', (ws) => { console.log('WebSocket connected'); setTimeout(() => { console.log("start"); setData() }, 100); clients.add(ws);
ws.on('message', (message) => { console.log('Received message:', message); });
ws.on('close', () => { console.log('WebSocket closed'); clients.delete(ws); }); });
let num = 87654 let now = 1000
setInterval(() => { setData() }, 15000);
function setData(){ console.log("function"); num += parseInt(Math.random()*500) now += parseInt(Math.random()*200) let data = { "vipNumber":num, "nowAddVip":now, "num3":parseInt(Math.random()*100), "num4":parseInt(Math.random()*100), "num5":parseInt(Math.random()*100), "num6":parseInt(Math.random()*100),
}; clients.forEach((client) => { if (client.readyState === WebSocket.OPEN) { client.send(JSON.stringify(data)); } }); }
|