wip
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
const net = require('net');
|
||||
const fs = require('fs');
|
||||
const socketPath = '/tmp/node-server.sock';
|
||||
const socketPath = '/tmp/oscar_watcher.sock';
|
||||
|
||||
//// UNIXSOCKET SERVER ////
|
||||
|
||||
let progvars = {};
|
||||
|
||||
@@ -15,7 +17,7 @@ try {
|
||||
}
|
||||
|
||||
const unix_socket_server = net.createServer((connection) => {
|
||||
console.log('Client connected.');
|
||||
console.log('UnixSocket Client connected.');
|
||||
|
||||
let buffer = '';
|
||||
|
||||
@@ -31,12 +33,12 @@ const unix_socket_server = net.createServer((connection) => {
|
||||
});
|
||||
|
||||
connection.on('end', () => {
|
||||
console.log('Client disconnected.');
|
||||
console.log('UnixSocket Client disconnected.');
|
||||
});
|
||||
});
|
||||
|
||||
unix_socket_server.listen(socketPath, () => {
|
||||
console.log(`Server listening on ${socketPath}`);
|
||||
console.log(`UnixSocket Server listening on ${socketPath}`);
|
||||
});
|
||||
|
||||
function processMessage(message) {
|
||||
@@ -49,7 +51,7 @@ function processMessage(message) {
|
||||
const timestamp = new Date().toISOString();
|
||||
const logEntry = `log_time="${timestamp}";\n${diff}\n`;
|
||||
|
||||
fs.writeFile('variable_changes.log', logEntry, { flag: 'a' }, (err) => {
|
||||
fs.writeFile('/data/openpilot/logs/watcher.log', logEntry, { flag: 'a' }, (err) => {
|
||||
if (err) {
|
||||
console.error('Error writing to log file:', err);
|
||||
}
|
||||
@@ -103,6 +105,8 @@ function calculateDiff(oldValue, newValue) {
|
||||
return changes.join('\n');
|
||||
}
|
||||
|
||||
//// WEBSOCKET SERVER ////
|
||||
|
||||
const WebSocket = require('ws');
|
||||
const http = require('http');
|
||||
const url = require('url');
|
||||
@@ -156,5 +160,37 @@ function send_ws_message(message) {
|
||||
// Start the HTTP server
|
||||
const PORT = 3001; // Ensure this port is different from the UNIX socket server if running on the same machine
|
||||
websocket_server.listen(PORT, () => {
|
||||
console.log(`WebSocket server is running on port ${PORT}`);
|
||||
console.log(`WebSocket listening on port ${PORT}`);
|
||||
});
|
||||
|
||||
//// HTTP SERVER ////
|
||||
|
||||
const http = require('http');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const hostname = '0.0.0.0';
|
||||
const port = 1024;
|
||||
|
||||
const server = http.createServer((req, res) => {
|
||||
if(req.url === '/') {
|
||||
// Serve the HTML file
|
||||
fs.readFile(path.join(__dirname, 'index.html'), (err, data) => {
|
||||
if(err) {
|
||||
res.writeHead(500);
|
||||
res.end('Error loading index.html');
|
||||
return;
|
||||
}
|
||||
res.writeHead(200, {'Content-Type': 'text/html'});
|
||||
res.end(data);
|
||||
});
|
||||
} else {
|
||||
// Handle 404
|
||||
res.writeHead(404);
|
||||
res.end('Not found');
|
||||
}
|
||||
});
|
||||
|
||||
server.listen(port, hostname, () => {
|
||||
console.log(`Server running at http://${hostname}:${port}/`);
|
||||
});
|
||||
Reference in New Issue
Block a user