import { EventEmitter } from 'node:events'; import { Buffer } from 'node:buffer'; export interface SocketOptions { type: 'udp4' | 'udp6'; reuseAddr?: boolean; reusePort?: boolean; ipv6Only?: boolean; recvBufferSize?: number; sendBufferSize?: number; signal?: AbortSignal; } export interface AddressInfo { address: string; family: string; port: number; } /** * dgram.Socket — UDP socket wrapping Gio.Socket. */ interface RemoteAddressInfo { address: string; family: string; port: number; } export declare class Socket extends EventEmitter { readonly type: 'udp4' | 'udp6'; private _socket; private _bound; private _closed; private _receiving; private _address; private _cancellable; private _readSource; private _reuseAddr; private _connected; private _remoteAddress; constructor(options: SocketOptions | string); /** * Bind the socket to a port and optional address. */ bind(port?: number | { port?: number; address?: string; exclusive?: boolean; }, address?: string | (() => void), callback?: () => void): this; /** * Send a message. */ send(msg: Buffer | string | Uint8Array | (Buffer | string | Uint8Array)[], offset?: number | ((err: Error | null, bytes: number) => void), length?: number, port?: number, address?: string | ((err: Error | null, bytes: number) => void), callback?: (err: Error | null, bytes: number) => void): void; private _autoBind; /** Socket family that matches `this.type` (udp4 → IPv4, udp6 → IPv6). */ private _socketFamily; /** True when `addr` can be sent to from a socket bound with `this._socketFamily()`. */ private _isAddressCompatible; /** Build an EINVAL error for a destination whose family doesn't match the socket. * Matches Node.js dgram behavior (node reports EINVAL from sendto(2) when the * destination address family is incompatible with the bound socket). */ private _mismatchError; private _resolveAndSend; private _toBuffer; private _toBufferSlice; /** * Close the socket. */ close(callback?: () => void): this; /** * Associate the socket with a remote address/port (connected UDP). * After connect(), send() can omit address and port. */ connect(port: number, address?: string | (() => void), callback?: () => void): void; /** * Dissociate a connected socket from its remote address. */ disconnect(): void; /** * Returns the remote address of a connected socket. * Throws ERR_SOCKET_DGRAM_NOT_CONNECTED if not connected. */ remoteAddress(): RemoteAddressInfo; /** * Get the bound address info. */ address(): AddressInfo; /** * Set the broadcast flag. */ setBroadcast(flag: boolean): void; /** * Set the TTL. */ setTTL(ttl: number): number; /** * Set multicast TTL. */ setMulticastTTL(ttl: number): number; /** * Set multicast loopback. */ setMulticastLoopback(flag: boolean): boolean; /** * Add multicast group membership. */ addMembership(multicastAddress: string, multicastInterface?: string): void; /** * Drop multicast group membership. */ dropMembership(multicastAddress: string, multicastInterface?: string): void; /** * Set multicast interface. */ setMulticastInterface(_interfaceAddress: string): void; /** Ref the socket (keep event loop alive). */ ref(): this; /** Unref the socket (allow event loop to exit). */ unref(): this; /** Get/Set receive buffer size. */ getRecvBufferSize(): number; setRecvBufferSize(_size: number): void; /** Get/Set send buffer size. */ getSendBufferSize(): number; setSendBufferSize(_size: number): void; /** * Start receiving messages in background. */ private _startReceiving; private _receiveLoop; } /** * Create a UDP socket. */ export declare function createSocket(type: 'udp4' | 'udp6' | SocketOptions, callback?: (msg: Buffer, rinfo: AddressInfo) => void): Socket; declare const _default: { Socket: typeof Socket; createSocket: typeof createSocket; }; export default _default;