CoolFace
Apppublic

Pinsave/counterstrike

sourceHugging Faceupdated 3mo agoView on Hugging Face
1likes
net.d.ts1033 linesDownload Raw Back to node
1/**2 * > Stability: 2 - Stable3 *4 * The `node:net` module provides an asynchronous network API for creating stream-based5 * TCP or `IPC` servers ({@link createServer}) and clients6 * ({@link createConnection}).7 *8 * It can be accessed using:9 *10 * ```js11 * import net from 'node:net';12 * ```13 * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/net.js)14 */15declare module "net" {16    import * as stream from "node:stream";17    import { Abortable, EventEmitter } from "node:events";18    import * as dns from "node:dns";19    type LookupFunction = (20        hostname: string,21        options: dns.LookupOptions,22        callback: (err: NodeJS.ErrnoException | null, address: string | dns.LookupAddress[], family?: number) => void,23    ) => void;24    interface AddressInfo {25        address: string;26        family: string;27        port: number;28    }29    interface SocketConstructorOpts {30        fd?: number | undefined;31        allowHalfOpen?: boolean | undefined;32        onread?: OnReadOpts | undefined;33        readable?: boolean | undefined;34        writable?: boolean | undefined;35        signal?: AbortSignal;36    }37    interface OnReadOpts {38        buffer: Uint8Array | (() => Uint8Array);39        /**40         * This function is called for every chunk of incoming data.41         * Two arguments are passed to it: the number of bytes written to `buffer` and a reference to `buffer`.42         * Return `false` from this function to implicitly `pause()` the socket.43         */44        callback(bytesWritten: number, buffer: Uint8Array): boolean;45    }46    interface TcpSocketConnectOpts {47        port: number;48        host?: string | undefined;49        localAddress?: string | undefined;50        localPort?: number | undefined;51        hints?: number | undefined;52        family?: number | undefined;53        lookup?: LookupFunction | undefined;54        noDelay?: boolean | undefined;55        keepAlive?: boolean | undefined;56        keepAliveInitialDelay?: number | undefined;57        /**58         * @since v18.13.059         */60        autoSelectFamily?: boolean | undefined;61        /**62         * @since v18.13.063         */64        autoSelectFamilyAttemptTimeout?: number | undefined;65        blockList?: BlockList | undefined;66    }67    interface IpcSocketConnectOpts {68        path: string;69    }70    type SocketConnectOpts = TcpSocketConnectOpts | IpcSocketConnectOpts;71    type SocketReadyState = "opening" | "open" | "readOnly" | "writeOnly" | "closed";72    /**73     * This class is an abstraction of a TCP socket or a streaming `IPC` endpoint74     * (uses named pipes on Windows, and Unix domain sockets otherwise). It is also75     * an `EventEmitter`.76     *77     * A `net.Socket` can be created by the user and used directly to interact with78     * a server. For example, it is returned by {@link createConnection},79     * so the user can use it to talk to the server.80     *81     * It can also be created by Node.js and passed to the user when a connection82     * is received. For example, it is passed to the listeners of a `'connection'` event emitted on a {@link Server}, so the user can use83     * it to interact with the client.84     * @since v0.3.485     */86    class Socket extends stream.Duplex {87        constructor(options?: SocketConstructorOpts);88        /**89         * Destroys the socket after all data is written. If the `finish` event was already emitted the socket is destroyed immediately.90         * If the socket is still writable it implicitly calls `socket.end()`.91         * @since v0.3.492         */93        destroySoon(): void;94        /**95         * Sends data on the socket. The second parameter specifies the encoding in the96         * case of a string. It defaults to UTF8 encoding.97         *98         * Returns `true` if the entire data was flushed successfully to the kernel99         * buffer. Returns `false` if all or part of the data was queued in user memory.`'drain'` will be emitted when the buffer is again free.100         *101         * The optional `callback` parameter will be executed when the data is finally102         * written out, which may not be immediately.103         *104         * See `Writable` stream `write()` method for more105         * information.106         * @since v0.1.90107         * @param [encoding='utf8'] Only used when data is `string`.108         */109        write(buffer: Uint8Array | string, cb?: (err?: Error | null) => void): boolean;110        write(str: Uint8Array | string, encoding?: BufferEncoding, cb?: (err?: Error | null) => void): boolean;111        /**112         * Initiate a connection on a given socket.113         *114         * Possible signatures:115         *116         * * `socket.connect(options[, connectListener])`117         * * `socket.connect(path[, connectListener])` for `IPC` connections.118         * * `socket.connect(port[, host][, connectListener])` for TCP connections.119         * * Returns: `net.Socket` The socket itself.120         *121         * This function is asynchronous. When the connection is established, the `'connect'` event will be emitted. If there is a problem connecting,122         * instead of a `'connect'` event, an `'error'` event will be emitted with123         * the error passed to the `'error'` listener.124         * The last parameter `connectListener`, if supplied, will be added as a listener125         * for the `'connect'` event **once**.126         *127         * This function should only be used for reconnecting a socket after`'close'` has been emitted or otherwise it may lead to undefined128         * behavior.129         */130        connect(options: SocketConnectOpts, connectionListener?: () => void): this;131        connect(port: number, host: string, connectionListener?: () => void): this;132        connect(port: number, connectionListener?: () => void): this;133        connect(path: string, connectionListener?: () => void): this;134        /**135         * Set the encoding for the socket as a `Readable Stream`. See `readable.setEncoding()` for more information.136         * @since v0.1.90137         * @return The socket itself.138         */139        setEncoding(encoding?: BufferEncoding): this;140        /**141         * Pauses the reading of data. That is, `'data'` events will not be emitted.142         * Useful to throttle back an upload.143         * @return The socket itself.144         */145        pause(): this;146        /**147         * Close the TCP connection by sending an RST packet and destroy the stream.148         * If this TCP socket is in connecting status, it will send an RST packet and destroy this TCP socket once it is connected.149         * Otherwise, it will call `socket.destroy` with an `ERR_SOCKET_CLOSED` Error.150         * If this is not a TCP socket (for example, a pipe), calling this method will immediately throw an `ERR_INVALID_HANDLE_TYPE` Error.151         * @since v18.3.0, v16.17.0152         */153        resetAndDestroy(): this;154        /**155         * Resumes reading after a call to `socket.pause()`.156         * @return The socket itself.157         */158        resume(): this;159        /**160         * Sets the socket to timeout after `timeout` milliseconds of inactivity on161         * the socket. By default `net.Socket` do not have a timeout.162         *163         * When an idle timeout is triggered the socket will receive a `'timeout'` event but the connection will not be severed. The user must manually call `socket.end()` or `socket.destroy()` to164         * end the connection.165         *166         * ```js167         * socket.setTimeout(3000);168         * socket.on('timeout', () => {169         *   console.log('socket timeout');170         *   socket.end();171         * });172         * ```173         *174         * If `timeout` is 0, then the existing idle timeout is disabled.175         *176         * The optional `callback` parameter will be added as a one-time listener for the `'timeout'` event.177         * @since v0.1.90178         * @return The socket itself.179         */180        setTimeout(timeout: number, callback?: () => void): this;181        /**182         * Enable/disable the use of Nagle's algorithm.183         *184         * When a TCP connection is created, it will have Nagle's algorithm enabled.185         *186         * Nagle's algorithm delays data before it is sent via the network. It attempts187         * to optimize throughput at the expense of latency.188         *189         * Passing `true` for `noDelay` or not passing an argument will disable Nagle's190         * algorithm for the socket. Passing `false` for `noDelay` will enable Nagle's191         * algorithm.192         * @since v0.1.90193         * @param [noDelay=true]194         * @return The socket itself.195         */196        setNoDelay(noDelay?: boolean): this;197        /**198         * Enable/disable keep-alive functionality, and optionally set the initial199         * delay before the first keepalive probe is sent on an idle socket.200         *201         * Set `initialDelay` (in milliseconds) to set the delay between the last202         * data packet received and the first keepalive probe. Setting `0` for`initialDelay` will leave the value unchanged from the default203         * (or previous) setting.204         *205         * Enabling the keep-alive functionality will set the following socket options:206         *207         * * `SO_KEEPALIVE=1`208         * * `TCP_KEEPIDLE=initialDelay`209         * * `TCP_KEEPCNT=10`210         * * `TCP_KEEPINTVL=1`211         * @since v0.1.92212         * @param [enable=false]213         * @param [initialDelay=0]214         * @return The socket itself.215         */216        setKeepAlive(enable?: boolean, initialDelay?: number): this;217        /**218         * Returns the bound `address`, the address `family` name and `port` of the219         * socket as reported by the operating system:`{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`220         * @since v0.1.90221         */222        address(): AddressInfo | {};223        /**224         * Calling `unref()` on a socket will allow the program to exit if this is the only225         * active socket in the event system. If the socket is already `unref`ed calling`unref()` again will have no effect.226         * @since v0.9.1227         * @return The socket itself.228         */229        unref(): this;230        /**231         * Opposite of `unref()`, calling `ref()` on a previously `unref`ed socket will _not_ let the program exit if it's the only socket left (the default behavior).232         * If the socket is `ref`ed calling `ref` again will have no effect.233         * @since v0.9.1234         * @return The socket itself.235         */236        ref(): this;237        /**238         * This property is only present if the family autoselection algorithm is enabled in `socket.connect(options)`239         * and it is an array of the addresses that have been attempted.240         *241         * Each address is a string in the form of `$IP:$PORT`.242         * If the connection was successful, then the last address is the one that the socket is currently connected to.243         * @since v19.4.0244         */245        readonly autoSelectFamilyAttemptedAddresses: string[];246        /**247         * This property shows the number of characters buffered for writing. The buffer248         * may contain strings whose length after encoding is not yet known. So this number249         * is only an approximation of the number of bytes in the buffer.250         *251         * `net.Socket` has the property that `socket.write()` always works. This is to252         * help users get up and running quickly. The computer cannot always keep up253         * with the amount of data that is written to a socket. The network connection254         * simply might be too slow. Node.js will internally queue up the data written to a255         * socket and send it out over the wire when it is possible.256         *257         * The consequence of this internal buffering is that memory may grow.258         * Users who experience large or growing `bufferSize` should attempt to259         * "throttle" the data flows in their program with `socket.pause()` and `socket.resume()`.260         * @since v0.3.8261         * @deprecated Since v14.6.0 - Use `writableLength` instead.262         */263        readonly bufferSize: number;264        /**265         * The amount of received bytes.266         * @since v0.5.3267         */268        readonly bytesRead: number;269        /**270         * The amount of bytes sent.271         * @since v0.5.3272         */273        readonly bytesWritten: number;274        /**275         * If `true`, `socket.connect(options[, connectListener])` was276         * called and has not yet finished. It will stay `true` until the socket becomes277         * connected, then it is set to `false` and the `'connect'` event is emitted. Note278         * that the `socket.connect(options[, connectListener])` callback is a listener for the `'connect'` event.279         * @since v6.1.0280         */281        readonly connecting: boolean;282        /**283         * This is `true` if the socket is not connected yet, either because `.connect()`has not yet been called or because it is still in the process of connecting284         * (see `socket.connecting`).285         * @since v11.2.0, v10.16.0286         */287        readonly pending: boolean;288        /**289         * See `writable.destroyed` for further details.290         */291        readonly destroyed: boolean;292        /**293         * The string representation of the local IP address the remote client is294         * connecting on. For example, in a server listening on `'0.0.0.0'`, if a client295         * connects on `'192.168.1.1'`, the value of `socket.localAddress` would be`'192.168.1.1'`.296         * @since v0.9.6297         */298        readonly localAddress?: string;299        /**300         * The numeric representation of the local port. For example, `80` or `21`.301         * @since v0.9.6302         */303        readonly localPort?: number;304        /**305         * The string representation of the local IP family. `'IPv4'` or `'IPv6'`.306         * @since v18.8.0, v16.18.0307         */308        readonly localFamily?: string;309        /**310         * This property represents the state of the connection as a string.311         *312         * * If the stream is connecting `socket.readyState` is `opening`.313         * * If the stream is readable and writable, it is `open`.314         * * If the stream is readable and not writable, it is `readOnly`.315         * * If the stream is not readable and writable, it is `writeOnly`.316         * @since v0.5.0317         */318        readonly readyState: SocketReadyState;319        /**320         * The string representation of the remote IP address. For example,`'74.125.127.100'` or `'2001:4860:a005::68'`. Value may be `undefined` if321         * the socket is destroyed (for example, if the client disconnected).322         * @since v0.5.10323         */324        readonly remoteAddress?: string | undefined;325        /**326         * The string representation of the remote IP family. `'IPv4'` or `'IPv6'`. Value may be `undefined` if327         * the socket is destroyed (for example, if the client disconnected).328         * @since v0.11.14329         */330        readonly remoteFamily?: string | undefined;331        /**332         * The numeric representation of the remote port. For example, `80` or `21`. Value may be `undefined` if333         * the socket is destroyed (for example, if the client disconnected).334         * @since v0.5.10335         */336        readonly remotePort?: number | undefined;337        /**338         * The socket timeout in milliseconds as set by `socket.setTimeout()`.339         * It is `undefined` if a timeout has not been set.340         * @since v10.7.0341         */342        readonly timeout?: number | undefined;343        /**344         * Half-closes the socket. i.e., it sends a FIN packet. It is possible the345         * server will still send some data.346         *347         * See `writable.end()` for further details.348         * @since v0.1.90349         * @param [encoding='utf8'] Only used when data is `string`.350         * @param callback Optional callback for when the socket is finished.351         * @return The socket itself.352         */353        end(callback?: () => void): this;354        end(buffer: Uint8Array | string, callback?: () => void): this;355        end(str: Uint8Array | string, encoding?: BufferEncoding, callback?: () => void): this;356        /**357         * events.EventEmitter358         *   1. close359         *   2. connect360         *   3. connectionAttempt361         *   4. connectionAttemptFailed362         *   5. connectionAttemptTimeout363         *   6. data364         *   7. drain365         *   8. end366         *   9. error367         *   10. lookup368         *   11. ready369         *   12. timeout370         */371        addListener(event: string, listener: (...args: any[]) => void): this;372        addListener(event: "close", listener: (hadError: boolean) => void): this;373        addListener(event: "connect", listener: () => void): this;374        addListener(event: "connectionAttempt", listener: (ip: string, port: number, family: number) => void): this;375        addListener(376            event: "connectionAttemptFailed",377            listener: (ip: string, port: number, family: number, error: Error) => void,378        ): this;379        addListener(380            event: "connectionAttemptTimeout",381            listener: (ip: string, port: number, family: number) => void,382        ): this;383        addListener(event: "data", listener: (data: Buffer) => void): this;384        addListener(event: "drain", listener: () => void): this;385        addListener(event: "end", listener: () => void): this;386        addListener(event: "error", listener: (err: Error) => void): this;387        addListener(388            event: "lookup",389            listener: (err: Error, address: string, family: string | number, host: string) => void,390        ): this;391        addListener(event: "ready", listener: () => void): this;392        addListener(event: "timeout", listener: () => void): this;393        emit(event: string | symbol, ...args: any[]): boolean;394        emit(event: "close", hadError: boolean): boolean;395        emit(event: "connect"): boolean;396        emit(event: "connectionAttempt", ip: string, port: number, family: number): boolean;397        emit(event: "connectionAttemptFailed", ip: string, port: number, family: number, error: Error): boolean;398        emit(event: "connectionAttemptTimeout", ip: string, port: number, family: number): boolean;399        emit(event: "data", data: Buffer): boolean;400        emit(event: "drain"): boolean;401        emit(event: "end"): boolean;402        emit(event: "error", err: Error): boolean;403        emit(event: "lookup", err: Error, address: string, family: string | number, host: string): boolean;404        emit(event: "ready"): boolean;405        emit(event: "timeout"): boolean;406        on(event: string, listener: (...args: any[]) => void): this;407        on(event: "close", listener: (hadError: boolean) => void): this;408        on(event: "connect", listener: () => void): this;409        on(event: "connectionAttempt", listener: (ip: string, port: number, family: number) => void): this;410        on(411            event: "connectionAttemptFailed",412            listener: (ip: string, port: number, family: number, error: Error) => void,413        ): this;414        on(event: "connectionAttemptTimeout", listener: (ip: string, port: number, family: number) => void): this;415        on(event: "data", listener: (data: Buffer) => void): this;416        on(event: "drain", listener: () => void): this;417        on(event: "end", listener: () => void): this;418        on(event: "error", listener: (err: Error) => void): this;419        on(420            event: "lookup",421            listener: (err: Error, address: string, family: string | number, host: string) => void,422        ): this;423        on(event: "ready", listener: () => void): this;424        on(event: "timeout", listener: () => void): this;425        once(event: string, listener: (...args: any[]) => void): this;426        once(event: "close", listener: (hadError: boolean) => void): this;427        once(event: "connectionAttempt", listener: (ip: string, port: number, family: number) => void): this;428        once(429            event: "connectionAttemptFailed",430            listener: (ip: string, port: number, family: number, error: Error) => void,431        ): this;432        once(event: "connectionAttemptTimeout", listener: (ip: string, port: number, family: number) => void): this;433        once(event: "connect", listener: () => void): this;434        once(event: "data", listener: (data: Buffer) => void): this;435        once(event: "drain", listener: () => void): this;436        once(event: "end", listener: () => void): this;437        once(event: "error", listener: (err: Error) => void): this;438        once(439            event: "lookup",440            listener: (err: Error, address: string, family: string | number, host: string) => void,441        ): this;442        once(event: "ready", listener: () => void): this;443        once(event: "timeout", listener: () => void): this;444        prependListener(event: string, listener: (...args: any[]) => void): this;445        prependListener(event: "close", listener: (hadError: boolean) => void): this;446        prependListener(event: "connect", listener: () => void): this;447        prependListener(event: "connectionAttempt", listener: (ip: string, port: number, family: number) => void): this;448        prependListener(449            event: "connectionAttemptFailed",450            listener: (ip: string, port: number, family: number, error: Error) => void,451        ): this;452        prependListener(453            event: "connectionAttemptTimeout",454            listener: (ip: string, port: number, family: number) => void,455        ): this;456        prependListener(event: "data", listener: (data: Buffer) => void): this;457        prependListener(event: "drain", listener: () => void): this;458        prependListener(event: "end", listener: () => void): this;459        prependListener(event: "error", listener: (err: Error) => void): this;460        prependListener(461            event: "lookup",462            listener: (err: Error, address: string, family: string | number, host: string) => void,463        ): this;464        prependListener(event: "ready", listener: () => void): this;465        prependListener(event: "timeout", listener: () => void): this;466        prependOnceListener(event: string, listener: (...args: any[]) => void): this;467        prependOnceListener(event: "close", listener: (hadError: boolean) => void): this;468        prependOnceListener(event: "connect", listener: () => void): this;469        prependOnceListener(470            event: "connectionAttempt",471            listener: (ip: string, port: number, family: number) => void,472        ): this;473        prependOnceListener(474            event: "connectionAttemptFailed",475            listener: (ip: string, port: number, family: number, error: Error) => void,476        ): this;477        prependOnceListener(478            event: "connectionAttemptTimeout",479            listener: (ip: string, port: number, family: number) => void,480        ): this;481        prependOnceListener(event: "data", listener: (data: Buffer) => void): this;482        prependOnceListener(event: "drain", listener: () => void): this;483        prependOnceListener(event: "end", listener: () => void): this;484        prependOnceListener(event: "error", listener: (err: Error) => void): this;485        prependOnceListener(486            event: "lookup",487            listener: (err: Error, address: string, family: string | number, host: string) => void,488        ): this;489        prependOnceListener(event: "ready", listener: () => void): this;490        prependOnceListener(event: "timeout", listener: () => void): this;491    }492    interface ListenOptions extends Abortable {493        backlog?: number | undefined;494        exclusive?: boolean | undefined;495        host?: string | undefined;496        /**497         * @default false498         */499        ipv6Only?: boolean | undefined;500        reusePort?: boolean | undefined;501        path?: string | undefined;502        port?: number | undefined;503        readableAll?: boolean | undefined;504        writableAll?: boolean | undefined;505    }506    interface ServerOpts {507        /**508         * Indicates whether half-opened TCP connections are allowed.509         * @default false510         */511        allowHalfOpen?: boolean | undefined;512        /**513         * Indicates whether the socket should be paused on incoming connections.514         * @default false515         */516        pauseOnConnect?: boolean | undefined;517        /**518         * If set to `true`, it disables the use of Nagle's algorithm immediately after a new incoming connection is received.519         * @default false520         * @since v16.5.0521         */522        noDelay?: boolean | undefined;523        /**524         * If set to `true`, it enables keep-alive functionality on the socket immediately after a new incoming connection is received,525         * similarly on what is done in `socket.setKeepAlive([enable][, initialDelay])`.526         * @default false527         * @since v16.5.0528         */529        keepAlive?: boolean | undefined;530        /**531         * If set to a positive number, it sets the initial delay before the first keepalive probe is sent on an idle socket.532         * @default 0533         * @since v16.5.0534         */535        keepAliveInitialDelay?: number | undefined;536        /**537         * Optionally overrides all `net.Socket`s' `readableHighWaterMark` and `writableHighWaterMark`.538         * @default See [stream.getDefaultHighWaterMark()](https://nodejs.org/docs/latest-v24.x/api/stream.html#streamgetdefaulthighwatermarkobjectmode).539         * @since v18.17.0, v20.1.0540         */541        highWaterMark?: number | undefined;542        /**543         * `blockList` can be used for disabling inbound544         * access to specific IP addresses, IP ranges, or IP subnets. This does not545         * work if the server is behind a reverse proxy, NAT, etc. because the address546         * checked against the block list is the address of the proxy, or the one547         * specified by the NAT.548         * @since v22.13.0549         */550        blockList?: BlockList | undefined;551    }552    interface DropArgument {553        localAddress?: string;554        localPort?: number;555        localFamily?: string;556        remoteAddress?: string;557        remotePort?: number;558        remoteFamily?: string;559    }560    /**561     * This class is used to create a TCP or `IPC` server.562     * @since v0.1.90563     */564    class Server extends EventEmitter {565        constructor(connectionListener?: (socket: Socket) => void);566        constructor(options?: ServerOpts, connectionListener?: (socket: Socket) => void);567        /**568         * Start a server listening for connections. A `net.Server` can be a TCP or569         * an `IPC` server depending on what it listens to.570         *571         * Possible signatures:572         *573         * * `server.listen(handle[, backlog][, callback])`574         * * `server.listen(options[, callback])`575         * * `server.listen(path[, backlog][, callback])` for `IPC` servers576         * * `server.listen([port[, host[, backlog]]][, callback])` for TCP servers577         *578         * This function is asynchronous. When the server starts listening, the `'listening'` event will be emitted. The last parameter `callback`will be added as a listener for the `'listening'`579         * event.580         *581         * All `listen()` methods can take a `backlog` parameter to specify the maximum582         * length of the queue of pending connections. The actual length will be determined583         * by the OS through sysctl settings such as `tcp_max_syn_backlog` and `somaxconn` on Linux. The default value of this parameter is 511 (not 512).584         *585         * All {@link Socket} are set to `SO_REUSEADDR` (see [`socket(7)`](https://man7.org/linux/man-pages/man7/socket.7.html) for586         * details).587         *588         * The `server.listen()` method can be called again if and only if there was an589         * error during the first `server.listen()` call or `server.close()` has been590         * called. Otherwise, an `ERR_SERVER_ALREADY_LISTEN` error will be thrown.591         *592         * One of the most common errors raised when listening is `EADDRINUSE`.593         * This happens when another server is already listening on the requested`port`/`path`/`handle`. One way to handle this would be to retry594         * after a certain amount of time:595         *596         * ```js597         * server.on('error', (e) => {598         *   if (e.code === 'EADDRINUSE') {599         *     console.error('Address in use, retrying...');600         *     setTimeout(() => {601         *       server.close();602         *       server.listen(PORT, HOST);603         *     }, 1000);604         *   }605         * });606         * ```607         */608        listen(port?: number, hostname?: string, backlog?: number, listeningListener?: () => void): this;609        listen(port?: number, hostname?: string, listeningListener?: () => void): this;610        listen(port?: number, backlog?: number, listeningListener?: () => void): this;611        listen(port?: number, listeningListener?: () => void): this;612        listen(path: string, backlog?: number, listeningListener?: () => void): this;613        listen(path: string, listeningListener?: () => void): this;614        listen(options: ListenOptions, listeningListener?: () => void): this;615        listen(handle: any, backlog?: number, listeningListener?: () => void): this;616        listen(handle: any, listeningListener?: () => void): this;617        /**618         * Stops the server from accepting new connections and keeps existing619         * connections. This function is asynchronous, the server is finally closed620         * when all connections are ended and the server emits a `'close'` event.621         * The optional `callback` will be called once the `'close'` event occurs. Unlike622         * that event, it will be called with an `Error` as its only argument if the server623         * was not open when it was closed.624         * @since v0.1.90625         * @param callback Called when the server is closed.626         */627        close(callback?: (err?: Error) => void): this;628        /**629         * Returns the bound `address`, the address `family` name, and `port` of the server630         * as reported by the operating system if listening on an IP socket631         * (useful to find which port was assigned when getting an OS-assigned address):`{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`.632         *633         * For a server listening on a pipe or Unix domain socket, the name is returned634         * as a string.635         *636         * ```js637         * const server = net.createServer((socket) => {638         *   socket.end('goodbye\n');639         * }).on('error', (err) => {640         *   // Handle errors here.641         *   throw err;642         * });643         *644         * // Grab an arbitrary unused port.645         * server.listen(() => {646         *   console.log('opened server on', server.address());647         * });648         * ```649         *650         * `server.address()` returns `null` before the `'listening'` event has been651         * emitted or after calling `server.close()`.652         * @since v0.1.90653         */654        address(): AddressInfo | string | null;655        /**656         * Asynchronously get the number of concurrent connections on the server. Works657         * when sockets were sent to forks.658         *659         * Callback should take two arguments `err` and `count`.660         * @since v0.9.7661         */662        getConnections(cb: (error: Error | null, count: number) => void): this;663        /**664         * Opposite of `unref()`, calling `ref()` on a previously `unref`ed server will _not_ let the program exit if it's the only server left (the default behavior).665         * If the server is `ref`ed calling `ref()` again will have no effect.666         * @since v0.9.1667         */668        ref(): this;669        /**670         * Calling `unref()` on a server will allow the program to exit if this is the only671         * active server in the event system. If the server is already `unref`ed calling`unref()` again will have no effect.672         * @since v0.9.1673         */674        unref(): this;675        /**676         * Set this property to reject connections when the server's connection count gets677         * high.678         *679         * It is not recommended to use this option once a socket has been sent to a child680         * with `child_process.fork()`.681         * @since v0.2.0682         */683        maxConnections: number;684        connections: number;685        /**686         * Indicates whether or not the server is listening for connections.687         * @since v5.7.0688         */689        readonly listening: boolean;690        /**691         * events.EventEmitter692         *   1. close693         *   2. connection694         *   3. error695         *   4. listening696         *   5. drop697         */698        addListener(event: string, listener: (...args: any[]) => void): this;699        addListener(event: "close", listener: () => void): this;700        addListener(event: "connection", listener: (socket: Socket) => void): this;701        addListener(event: "error", listener: (err: Error) => void): this;702        addListener(event: "listening", listener: () => void): this;703        addListener(event: "drop", listener: (data?: DropArgument) => void): this;704        emit(event: string | symbol, ...args: any[]): boolean;705        emit(event: "close"): boolean;706        emit(event: "connection", socket: Socket): boolean;707        emit(event: "error", err: Error): boolean;708        emit(event: "listening"): boolean;709        emit(event: "drop", data?: DropArgument): boolean;710        on(event: string, listener: (...args: any[]) => void): this;711        on(event: "close", listener: () => void): this;712        on(event: "connection", listener: (socket: Socket) => void): this;713        on(event: "error", listener: (err: Error) => void): this;714        on(event: "listening", listener: () => void): this;715        on(event: "drop", listener: (data?: DropArgument) => void): this;716        once(event: string, listener: (...args: any[]) => void): this;717        once(event: "close", listener: () => void): this;718        once(event: "connection", listener: (socket: Socket) => void): this;719        once(event: "error", listener: (err: Error) => void): this;720        once(event: "listening", listener: () => void): this;721        once(event: "drop", listener: (data?: DropArgument) => void): this;722        prependListener(event: string, listener: (...args: any[]) => void): this;723        prependListener(event: "close", listener: () => void): this;724        prependListener(event: "connection", listener: (socket: Socket) => void): this;725        prependListener(event: "error", listener: (err: Error) => void): this;726        prependListener(event: "listening", listener: () => void): this;727        prependListener(event: "drop", listener: (data?: DropArgument) => void): this;728        prependOnceListener(event: string, listener: (...args: any[]) => void): this;729        prependOnceListener(event: "close", listener: () => void): this;730        prependOnceListener(event: "connection", listener: (socket: Socket) => void): this;731        prependOnceListener(event: "error", listener: (err: Error) => void): this;732        prependOnceListener(event: "listening", listener: () => void): this;733        prependOnceListener(event: "drop", listener: (data?: DropArgument) => void): this;734        /**735         * Calls {@link Server.close()} and returns a promise that fulfills when the server has closed.736         * @since v20.5.0737         */738        [Symbol.asyncDispose](): Promise<void>;739    }740    type IPVersion = "ipv4" | "ipv6";741    /**742     * The `BlockList` object can be used with some network APIs to specify rules for743     * disabling inbound or outbound access to specific IP addresses, IP ranges, or744     * IP subnets.745     * @since v15.0.0, v14.18.0746     */747    class BlockList {748        /**749         * Adds a rule to block the given IP address.750         * @since v15.0.0, v14.18.0751         * @param address An IPv4 or IPv6 address.752         * @param [type='ipv4'] Either `'ipv4'` or `'ipv6'`.753         */754        addAddress(address: string, type?: IPVersion): void;755        addAddress(address: SocketAddress): void;756        /**757         * Adds a rule to block a range of IP addresses from `start` (inclusive) to`end` (inclusive).758         * @since v15.0.0, v14.18.0759         * @param start The starting IPv4 or IPv6 address in the range.760         * @param end The ending IPv4 or IPv6 address in the range.761         * @param [type='ipv4'] Either `'ipv4'` or `'ipv6'`.762         */763        addRange(start: string, end: string, type?: IPVersion): void;764        addRange(start: SocketAddress, end: SocketAddress): void;765        /**766         * Adds a rule to block a range of IP addresses specified as a subnet mask.767         * @since v15.0.0, v14.18.0768         * @param net The network IPv4 or IPv6 address.769         * @param prefix The number of CIDR prefix bits. For IPv4, this must be a value between `0` and `32`. For IPv6, this must be between `0` and `128`.770         * @param [type='ipv4'] Either `'ipv4'` or `'ipv6'`.771         */772        addSubnet(net: SocketAddress, prefix: number): void;773        addSubnet(net: string, prefix: number, type?: IPVersion): void;774        /**775         * Returns `true` if the given IP address matches any of the rules added to the`BlockList`.776         *777         * ```js778         * const blockList = new net.BlockList();779         * blockList.addAddress('123.123.123.123');780         * blockList.addRange('10.0.0.1', '10.0.0.10');781         * blockList.addSubnet('8592:757c:efae:4e45::', 64, 'ipv6');782         *783         * console.log(blockList.check('123.123.123.123'));  // Prints: true784         * console.log(blockList.check('10.0.0.3'));  // Prints: true785         * console.log(blockList.check('222.111.111.222'));  // Prints: false786         *787         * // IPv6 notation for IPv4 addresses works:788         * console.log(blockList.check('::ffff:7b7b:7b7b', 'ipv6')); // Prints: true789         * console.log(blockList.check('::ffff:123.123.123.123', 'ipv6')); // Prints: true790         * ```791         * @since v15.0.0, v14.18.0792         * @param address The IP address to check793         * @param [type='ipv4'] Either `'ipv4'` or `'ipv6'`.794         */795        check(address: SocketAddress): boolean;796        check(address: string, type?: IPVersion): boolean;797        /**798         * The list of rules added to the blocklist.799         * @since v15.0.0, v14.18.0800         */801        rules: readonly string[];802        /**803         * Returns `true` if the `value` is a `net.BlockList`.804         * @since v22.13.0805         * @param value Any JS value806         */807        static isBlockList(value: unknown): value is BlockList;808    }809    interface TcpNetConnectOpts extends TcpSocketConnectOpts, SocketConstructorOpts {810        timeout?: number | undefined;811    }812    interface IpcNetConnectOpts extends IpcSocketConnectOpts, SocketConstructorOpts {813        timeout?: number | undefined;814    }815    type NetConnectOpts = TcpNetConnectOpts | IpcNetConnectOpts;816    /**817     * Creates a new TCP or `IPC` server.818     *819     * If `allowHalfOpen` is set to `true`, when the other end of the socket820     * signals the end of transmission, the server will only send back the end of821     * transmission when `socket.end()` is explicitly called. For example, in the822     * context of TCP, when a FIN packed is received, a FIN packed is sent823     * back only when `socket.end()` is explicitly called. Until then the824     * connection is half-closed (non-readable but still writable). See `'end'` event and [RFC 1122](https://tools.ietf.org/html/rfc1122) (section 4.2.2.13) for more information.825     *826     * If `pauseOnConnect` is set to `true`, then the socket associated with each827     * incoming connection will be paused, and no data will be read from its handle.828     * This allows connections to be passed between processes without any data being829     * read by the original process. To begin reading data from a paused socket, call `socket.resume()`.830     *831     * The server can be a TCP server or an `IPC` server, depending on what it `listen()` to.832     *833     * Here is an example of a TCP echo server which listens for connections834     * on port 8124:835     *836     * ```js837     * import net from 'node:net';838     * const server = net.createServer((c) => {839     *   // 'connection' listener.840     *   console.log('client connected');841     *   c.on('end', () => {842     *     console.log('client disconnected');843     *   });844     *   c.write('hello\r\n');845     *   c.pipe(c);846     * });847     * server.on('error', (err) => {848     *   throw err;849     * });850     * server.listen(8124, () => {851     *   console.log('server bound');852     * });853     * ```854     *855     * Test this by using `telnet`:856     *857     * ```bash858     * telnet localhost 8124859     * ```860     *861     * To listen on the socket `/tmp/echo.sock`:862     *863     * ```js864     * server.listen('/tmp/echo.sock', () => {865     *   console.log('server bound');866     * });867     * ```868     *869     * Use `nc` to connect to a Unix domain socket server:870     *871     * ```bash872     * nc -U /tmp/echo.sock873     * ```874     * @since v0.5.0875     * @param connectionListener Automatically set as a listener for the {@link 'connection'} event.876     */877    function createServer(connectionListener?: (socket: Socket) => void): Server;878    function createServer(options?: ServerOpts, connectionListener?: (socket: Socket) => void): Server;879    /**880     * Aliases to {@link createConnection}.881     *882     * Possible signatures:883     *884     * * {@link connect}885     * * {@link connect} for `IPC` connections.886     * * {@link connect} for TCP connections.887     */888    function connect(options: NetConnectOpts, connectionListener?: () => void): Socket;889    function connect(port: number, host?: string, connectionListener?: () => void): Socket;890    function connect(path: string, connectionListener?: () => void): Socket;891    /**892     * A factory function, which creates a new {@link Socket},893     * immediately initiates connection with `socket.connect()`,894     * then returns the `net.Socket` that starts the connection.895     *896     * When the connection is established, a `'connect'` event will be emitted897     * on the returned socket. The last parameter `connectListener`, if supplied,898     * will be added as a listener for the `'connect'` event **once**.899     *900     * Possible signatures:901     *902     * * {@link createConnection}903     * * {@link createConnection} for `IPC` connections.904     * * {@link createConnection} for TCP connections.905     *906     * The {@link connect} function is an alias to this function.907     */908    function createConnection(options: NetConnectOpts, connectionListener?: () => void): Socket;909    function createConnection(port: number, host?: string, connectionListener?: () => void): Socket;910    function createConnection(path: string, connectionListener?: () => void): Socket;911    /**912     * Gets the current default value of the `autoSelectFamily` option of `socket.connect(options)`.913     * The initial default value is `true`, unless the command line option`--no-network-family-autoselection` is provided.914     * @since v19.4.0915     */916    function getDefaultAutoSelectFamily(): boolean;917    /**918     * Sets the default value of the `autoSelectFamily` option of `socket.connect(options)`.919     * @param value The new default value.920     * The initial default value is `true`, unless the command line option921     * `--no-network-family-autoselection` is provided.922     * @since v19.4.0923     */924    function setDefaultAutoSelectFamily(value: boolean): void;925    /**926     * Gets the current default value of the `autoSelectFamilyAttemptTimeout` option of `socket.connect(options)`.927     * The initial default value is `250` or the value specified via the command line option `--network-family-autoselection-attempt-timeout`.928     * @returns The current default value of the `autoSelectFamilyAttemptTimeout` option.929     * @since v19.8.0, v18.8.0930     */931    function getDefaultAutoSelectFamilyAttemptTimeout(): number;932    /**933     * Sets the default value of the `autoSelectFamilyAttemptTimeout` option of `socket.connect(options)`.934     * @param value The new default value, which must be a positive number. If the number is less than `10`, the value `10` is used instead. The initial default value is `250` or the value specified via the command line935     * option `--network-family-autoselection-attempt-timeout`.936     * @since v19.8.0, v18.8.0937     */938    function setDefaultAutoSelectFamilyAttemptTimeout(value: number): void;939    /**940     * Returns `6` if `input` is an IPv6 address. Returns `4` if `input` is an IPv4941     * address in [dot-decimal notation](https://en.wikipedia.org/wiki/Dot-decimal_notation) with no leading zeroes. Otherwise, returns`0`.942     *943     * ```js944     * net.isIP('::1'); // returns 6945     * net.isIP('127.0.0.1'); // returns 4946     * net.isIP('127.000.000.001'); // returns 0947     * net.isIP('127.0.0.1/24'); // returns 0948     * net.isIP('fhqwhgads'); // returns 0949     * ```950     * @since v0.3.0951     */952    function isIP(input: string): number;953    /**954     * Returns `true` if `input` is an IPv4 address in [dot-decimal notation](https://en.wikipedia.org/wiki/Dot-decimal_notation) with no955     * leading zeroes. Otherwise, returns `false`.956     *957     * ```js958     * net.isIPv4('127.0.0.1'); // returns true959     * net.isIPv4('127.000.000.001'); // returns false960     * net.isIPv4('127.0.0.1/24'); // returns false961     * net.isIPv4('fhqwhgads'); // returns false962     * ```963     * @since v0.3.0964     */965    function isIPv4(input: string): boolean;966    /**967     * Returns `true` if `input` is an IPv6 address. Otherwise, returns `false`.968     *969     * ```js970     * net.isIPv6('::1'); // returns true971     * net.isIPv6('fhqwhgads'); // returns false972     * ```973     * @since v0.3.0974     */975    function isIPv6(input: string): boolean;976    interface SocketAddressInitOptions {977        /**978         * The network address as either an IPv4 or IPv6 string.979         * @default 127.0.0.1980         */981        address?: string | undefined;982        /**983         * @default `'ipv4'`984         */985        family?: IPVersion | undefined;986        /**987         * An IPv6 flow-label used only if `family` is `'ipv6'`.988         * @default 0989         */990        flowlabel?: number | undefined;991        /**992         * An IP port.993         * @default 0994         */995        port?: number | undefined;996    }997    /**998     * @since v15.14.0, v14.18.0999     */1000    class SocketAddress {1001        constructor(options: SocketAddressInitOptions);1002        /**1003         * Either \`'ipv4'\` or \`'ipv6'\`.1004         * @since v15.14.0, v14.18.01005         */1006        readonly address: string;1007        /**1008         * Either \`'ipv4'\` or \`'ipv6'\`.1009         * @since v15.14.0, v14.18.01010         */1011        readonly family: IPVersion;1012        /**1013         * @since v15.14.0, v14.18.01014         */1015        readonly port: number;1016        /**1017         * @since v15.14.0, v14.18.01018         */1019        readonly flowlabel: number;1020        /**1021         * @since v22.13.01022         * @param input An input string containing an IP address and optional port,1023         * e.g. `123.1.2.3:1234` or `[1::1]:1234`.1024         * @returns Returns a `SocketAddress` if parsing was successful.1025         * Otherwise returns `undefined`.1026         */1027        static parse(input: string): SocketAddress | undefined;1028    }1029}1030declare module "node:net" {1031    export * from "net";1032}1033