mirror of
https://github.com/nvms/prsm.git
synced 2025-12-16 08:00:53 +00:00
- Make connect() methods return Promises for better async control - Remove automatic connections in constructors to prevent race conditions - Handle ECONNRESET errors gracefully during disconnection - Add comprehensive test suite covering reconnection, timeouts, and concurrency
24 lines
585 B
TypeScript
24 lines
585 B
TypeScript
import { CodeError } from "../common/codeerror";
|
|
import { Connection } from "../common/connection";
|
|
import { CommandServer } from "../server/commandserver";
|
|
|
|
const server = new CommandServer({
|
|
host: "localhost",
|
|
port: 3351,
|
|
secure: false,
|
|
});
|
|
|
|
server.connect().catch((err) => {
|
|
console.error("Failed to start server:", err);
|
|
process.exit(1);
|
|
});
|
|
|
|
server.command(0, async (payload: any, connection: Connection) => {
|
|
console.log("RECV [0]:", payload);
|
|
return { ok: "OK" };
|
|
});
|
|
|
|
server.on("clientError", (error: CodeError) => {
|
|
console.log("clientError", error.code);
|
|
});
|