forked from UBCMint/mint-frontend-product
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
26 lines (20 loc) · 788 Bytes
/
server.js
File metadata and controls
26 lines (20 loc) · 788 Bytes
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
const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: 8080 });
wss.on('connection', (ws) => {
console.log('New client connected');
const interval = setInterval(() => {
const data = {
time: Date.now(), // Using milliseconds since epoch for time
signals: Array.from({ length: 5 }, () =>
Math.floor(Math.random() * 100)
), // Random values for 5 brain regions
};
ws.send(JSON.stringify(data));
console.log('Sent data:', data); // Log the data being sent
}, 3); // Sends data every 10ms
ws.on('close', () => {
clearInterval(interval);
console.log('Client disconnected');
});
});
console.log('WebSocket server is running on ws://localhost:8080');