network chunk v20
This commit is contained in:
@@ -1,14 +1,36 @@
|
||||
import {UdpServer} from "../network/udp/udp_server";
|
||||
import {TcpServer} from "../network/tcp/tcp_server";
|
||||
import {workerData} from "worker_threads";
|
||||
import { UdpServer } from "../network/udp/udp_server";
|
||||
import { TcpServer } from "../network/tcp/tcp_server";
|
||||
|
||||
let udpServer: UdpServer | null = null;
|
||||
let tcpServer: TcpServer | null = null;
|
||||
let udpServer: UdpServer | null
|
||||
let tcpServer: TcpServer | null
|
||||
|
||||
const {USER_UDP_PORT, USER_TCP_PORT, HOST} = workerData;
|
||||
// Retrieve data from environment variables
|
||||
const USER_UDP_PORT = parseInt(process.env.USER_UDP_PORT || '0', 10);
|
||||
const USER_TCP_PORT = parseInt(process.env.USER_TCP_PORT || '0', 10);
|
||||
const HOST = process.env.HOST || '';
|
||||
|
||||
// Initialize and start the servers
|
||||
udpServer = new UdpServer(HOST, USER_UDP_PORT);
|
||||
udpServer.start();
|
||||
|
||||
tcpServer = new TcpServer(HOST, USER_TCP_PORT);
|
||||
tcpServer.start();
|
||||
tcpServer.start();
|
||||
|
||||
process.on('SIGTERM', async () => {
|
||||
console.log('Received SIGTERM. Cleaning up...');
|
||||
await cleanupAndExit();
|
||||
});
|
||||
|
||||
process.on('SIGINT', async () => {
|
||||
console.log('Received SIGINT. Cleaning up...');
|
||||
await cleanupAndExit();
|
||||
});
|
||||
|
||||
async function cleanupAndExit() {
|
||||
// Perform any cleanup, such as closing connections, saving data, etc.
|
||||
// Example: if you have a server instance running, you may want to close it:
|
||||
// await server.close();
|
||||
|
||||
console.log('Cleanup complete. Exiting.');
|
||||
process.exit(0); // Exit with code 0 to indicate a clean exit
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user