API Reference
Complete constructor properties, method signatures, middleware chains, error tables, and TypeScript definitions for AfterLink.
Server Class Reference
Instantiated via new Server(options) or the wrapper helper createServer(options).
Server Options Parameters
| Option | Type | Default | Description |
|---|---|---|---|
| port | number | 8080 | TCP port configuration range. |
| host | string | '0.0.0.0' | Network interface address mapping. |
| idleTimeout | number | 60000 | Heartbeat delay threshold in milliseconds. |
| maxConnections | number | 10000 | Peak concurrent active sockets allowance limits. |
| tls | object | null | Pass key, cert buffers to activate secure TLS handshakes. |
Registers a callback listener for specific route requests or system handshake events, optionally verifying with Zod validation models.
Signature
server.on(route: string, handler: (socket, payload) => void, schema?: ZodSchema)
Injects global middleware functions into the connection processing stack (e.g. JWT validations or packet logging).
Signature
server.use(middleware: (socket, frame, next) => void)
Pushes pub/sub broadcasts directly onto channel topics. Server manages delivery lists and relays MSG_BROADCAST (0x05) frames automatically.
Signature
server.publish(channel: string, payload: any)
Transmits identical raw payload buffers to all active client sockets regardless of routing channel configurations.
Signature
server.broadcast(type: string, payload: any)
Closes raw TCP bindings gracefully, terminating keepalive heartbeats, and closing active connections correctly.
Signature
server.close(callback?: () => void): Promise<void>
Client Class Reference
Instantiated via new Client(options) or the wrapper helper createClient(options).
Client Options Parameters
| Option | Type | Default | Description |
|---|---|---|---|
| host | string | '127.0.0.1' | Host address of target AfterLink server. |
| port | number | 8080 | Destination binding TCP port range. |
| autoReconnect | boolean | true | Triggers socket re-connections upon socket drops. |
| maxRetries | number | 10 | Limits reconnection sequences before throwing errors. |
Triggers asynchronous handshakes to establish active socket bindings, or tears down established socket connections gracefully.
Signature
client.connect(): Promise<void> | client.disconnect(): Promise<void>
Dispatches structured RPC request packets (MSG_REQUEST) and returns matching Promise response elements resolving when server returns matching seq IDs.
Signature
client.request(route: string, body: any, options?: object): Promise<any>
Binds call functions to specific pub/sub streams. Instructs server routing layers by pushing MSG_SUBSCRIBE frames immediately.
Signature
client.subscribe(channel: string, callback: (payload, channel) => void): void
Publishes messages onto specified routing channels. Packages fields and transmits a single MSG_PUBLISH (0x03) packet.
Signature
client.publish(channel: string, payload: any): void
Establishes interactive, multi-frame streaming pipelines. Dispatches structured MSG_STREAM packets sequentially and ends with a MSG_STREAM_END marker.
Signature
client.stream(route: string, body: any): Promise<ReadableStream>
Protocol Error Codes
| Error Code | Error Constant | Diagnostic Description & Root Cause |
|---|---|---|
| 100 | ERR_MAGIC_MISMATCH | Invalid magic identifier bytes. Sockets from hostile scans or HTTP requests. |
| 101 | ERR_VERSION_UNSUPPORTED | The client version constant is incompatible with this server. |
| 400 | ERR_BAD_FRAME | Corrupt framing format structure, length offsets mismatch. |
| 401 | ERR_UNAUTHORIZED | Missing, invalid or expired handshake JWT authentication tokens. |
| 404 | ERR_ROUTE_NOT_FOUND | No matching method path listener exists on this server. |
| 422 | ERR_VALIDATION_FAILED | The frame payload model does not conform to the registered Zod validation schema. |
| 429 | ERR_RATE_LIMITED | Connection request counts exceeded maximum specified configurations. |
| 500 | ERR_INTERNAL_SERVER | Unhandled exception occurred in server-side handler code. |
TypeScript Declarations
Full TypeScript definitions for the core interfaces: