prsm/packages/duplex/src/example/server.ts
nvms 20fa3707ff fix: improve connection reliability and add comprehensive tests
- 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
2025-03-26 16:51:03 -04:00

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);
});