-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
35 lines (29 loc) · 1018 Bytes
/
server.js
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
// server.js
const express = require("express");
const http = require("http");
const socketIo = require("socket.io");
const app = express();
const server = http.createServer(app);
const io = socketIo(server);
// Serve static files from the 'public' directory
app.use(express.static("public"));
io.on("connection", (socket) => {
console.log("New client connected");
// Emit data every 2 seconds
setInterval(() => {
const newData = {
time: new Date().toLocaleTimeString(),
shortingRate: Math.random() * 10,
maxRate: Math.random() * 10,
minRate: Math.random() * 5,
averageRate: Math.random() * 7
};
console.log("Emitting data:", newData); // Verify data generation
io.emit("shortingData", newData); // Emit data to all connected clients
}, 2000);
socket.on("disconnect", () => {
console.log("Client disconnected");
});
});
const PORT = 3000;
server.listen(PORT, () => console.log(`Server running on port ${PORT}`));