@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
60 lines • 2.08 kB
TypeScript
/**
* Transport adapter over Node's `dgram` (UDP) socket.
*
* Designed for one-to-one peer relationships: each adapter instance talks to
* exactly one remote endpoint. For a server with many clients, create one
* adapter per client (typically after observing the first packet from each
* client's source `address:port`).
*
* The adapter binds locally on construction. To connect to a known remote
* (client pattern), pass `remote: { address, port }`. To accept inbound from
* any source (server pattern), leave `remote` unset and call
* {@link set_remote} after the first inbound packet identifies the peer.
*
* @author Alex Goldring
* @copyright Company Named Limited (c) 2025
*/
export class NodeUDPTransport extends Transport {
/**
* @param {{
* bind_address?: string,
* bind_port?: number,
* remote?: { address: string, port: number },
* }} [options]
*/
constructor({ bind_address, bind_port, remote }?: {
bind_address?: string;
bind_port?: number;
remote?: {
address: string;
port: number;
};
});
/** @type {import('node:dgram').Socket} */
socket: import('node:dgram').Socket;
/**
* Set or update the remote endpoint that {@link send} targets.
* @param {string} address
* @param {number} port
*/
set_remote(address: string, port: number): void;
/**
* Returns the locally bound `{address, port}`, useful for "what port did I
* end up on?" when constructed with `bind_port: 0`.
* @returns {{address: string, port: number}|null}
*/
get_bound_address(): {
address: string;
port: number;
} | null;
/**
* Block until the socket is bound and ready. Useful in tests; production
* code typically doesn't need to await this (sending before bind is fine —
* dgram queues internally).
* @returns {Promise<void>}
*/
connect(): Promise<void>;
#private;
}
import { Transport } from "../Transport.js";
//# sourceMappingURL=NodeUDPTransport.d.ts.map