1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | declare 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 = (hostname: string, options: dns.LookupOneOptions, callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void) => void;
|
20 | interface AddressInfo {
|
21 | address: string;
|
22 | family: string;
|
23 | port: number;
|
24 | }
|
25 | interface SocketConstructorOpts {
|
26 | fd?: number | undefined;
|
27 | allowHalfOpen?: boolean | undefined;
|
28 | readable?: boolean | undefined;
|
29 | writable?: boolean | undefined;
|
30 | signal?: AbortSignal;
|
31 | }
|
32 | interface OnReadOpts {
|
33 | buffer: Uint8Array | (() => Uint8Array);
|
34 | /**
|
35 | * This function is called for every chunk of incoming data.
|
36 | * Two arguments are passed to it: the number of bytes written to buffer and a reference to buffer.
|
37 | * Return false from this function to implicitly pause() the socket.
|
38 | */
|
39 | callback(bytesWritten: number, buf: Uint8Array): boolean;
|
40 | }
|
41 | interface ConnectOpts {
|
42 | /**
|
43 | * If specified, incoming data is stored in a single buffer and passed to the supplied callback when data arrives on the socket.
|
44 | * Note: this will cause the streaming functionality to not provide any data, however events like 'error', 'end', and 'close' will
|
45 | * still be emitted as normal and methods like pause() and resume() will also behave as expected.
|
46 | */
|
47 | onread?: OnReadOpts | undefined;
|
48 | }
|
49 | interface TcpSocketConnectOpts extends ConnectOpts {
|
50 | port: number;
|
51 | host?: string | undefined;
|
52 | localAddress?: string | undefined;
|
53 | localPort?: number | undefined;
|
54 | hints?: number | undefined;
|
55 | family?: number | undefined;
|
56 | lookup?: LookupFunction | undefined;
|
57 | }
|
58 | interface IpcSocketConnectOpts extends ConnectOpts {
|
59 | path: string;
|
60 | }
|
61 | type SocketConnectOpts = TcpSocketConnectOpts | IpcSocketConnectOpts;
|
62 | /**
|
63 | * This class is an abstraction of a TCP socket or a streaming `IPC` endpoint
|
64 | * (uses named pipes on Windows, and Unix domain sockets otherwise). It is also
|
65 | * an `EventEmitter`.
|
66 | *
|
67 | * A `net.Socket` can be created by the user and used directly to interact with
|
68 | * a server. For example, it is returned by {@link createConnection},
|
69 | * so the user can use it to talk to the server.
|
70 | *
|
71 | * It can also be created by Node.js and passed to the user when a connection
|
72 | * is received. For example, it is passed to the listeners of a `'connection'` event emitted on a {@link Server}, so the user can use
|
73 | * it to interact with the client.
|
74 | * @since v0.3.4
|
75 | */
|
76 | class Socket extends stream.Duplex {
|
77 | constructor(options?: SocketConstructorOpts);
|
78 | /**
|
79 | * Sends data on the socket. The second parameter specifies the encoding in the
|
80 | * case of a string. It defaults to UTF8 encoding.
|
81 | *
|
82 | * Returns `true` if the entire data was flushed successfully to the kernel
|
83 | * 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.
|
84 | *
|
85 | * The optional `callback` parameter will be executed when the data is finally
|
86 | * written out, which may not be immediately.
|
87 | *
|
88 | * See `Writable` stream `write()` method for more
|
89 | * information.
|
90 | * @since v0.1.90
|
91 | * @param [encoding='utf8'] Only used when data is `string`.
|
92 | */
|
93 | write(buffer: Uint8Array | string, cb?: (err?: Error) => void): boolean;
|
94 | write(str: Uint8Array | string, encoding?: BufferEncoding, cb?: (err?: Error) => void): boolean;
|
95 | /**
|
96 | * Initiate a connection on a given socket.
|
97 | *
|
98 | * Possible signatures:
|
99 | *
|
100 | * * `socket.connect(options[, connectListener])`
|
101 | * * `socket.connect(path[, connectListener])` for `IPC` connections.
|
102 | * * `socket.connect(port[, host][, connectListener])` for TCP connections.
|
103 | * * Returns: `net.Socket` The socket itself.
|
104 | *
|
105 | * This function is asynchronous. When the connection is established, the `'connect'` event will be emitted. If there is a problem connecting,
|
106 | * instead of a `'connect'` event, an `'error'` event will be emitted with
|
107 | * the error passed to the `'error'` listener.
|
108 | * The last parameter `connectListener`, if supplied, will be added as a listener
|
109 | * for the `'connect'` event **once**.
|
110 | *
|
111 | * This function should only be used for reconnecting a socket after`'close'` has been emitted or otherwise it may lead to undefined
|
112 | * behavior.
|
113 | */
|
114 | connect(options: SocketConnectOpts, connectionListener?: () => void): this;
|
115 | connect(port: number, host: string, connectionListener?: () => void): this;
|
116 | connect(port: number, connectionListener?: () => void): this;
|
117 | connect(path: string, connectionListener?: () => void): this;
|
118 | /**
|
119 | * Set the encoding for the socket as a `Readable Stream`. See `readable.setEncoding()` for more information.
|
120 | * @since v0.1.90
|
121 | * @return The socket itself.
|
122 | */
|
123 | setEncoding(encoding?: BufferEncoding): this;
|
124 | /**
|
125 | * Pauses the reading of data. That is, `'data'` events will not be emitted.
|
126 | * Useful to throttle back an upload.
|
127 | * @return The socket itself.
|
128 | */
|
129 | pause(): this;
|
130 | /**
|
131 | * Resumes reading after a call to `socket.pause()`.
|
132 | * @return The socket itself.
|
133 | */
|
134 | resume(): this;
|
135 | /**
|
136 | * Sets the socket to timeout after `timeout` milliseconds of inactivity on
|
137 | * the socket. By default `net.Socket` do not have a timeout.
|
138 | *
|
139 | * 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()` to
|
140 | * end the connection.
|
141 | *
|
142 | * ```js
|
143 | * socket.setTimeout(3000);
|
144 | * socket.on('timeout', () => {
|
145 | * console.log('socket timeout');
|
146 | * socket.end();
|
147 | * });
|
148 | * ```
|
149 | *
|
150 | * If `timeout` is 0, then the existing idle timeout is disabled.
|
151 | *
|
152 | * The optional `callback` parameter will be added as a one-time listener for the `'timeout'` event.
|
153 | * @since v0.1.90
|
154 | * @return The socket itself.
|
155 | */
|
156 | setTimeout(timeout: number, callback?: () => void): this;
|
157 | /**
|
158 | * Enable/disable the use of Nagle's algorithm.
|
159 | *
|
160 | * When a TCP connection is created, it will have Nagle's algorithm enabled.
|
161 | *
|
162 | * Nagle's algorithm delays data before it is sent via the network. It attempts
|
163 | * to optimize throughput at the expense of latency.
|
164 | *
|
165 | * Passing `true` for `noDelay` or not passing an argument will disable Nagle's
|
166 | * algorithm for the socket. Passing `false` for `noDelay` will enable Nagle's
|
167 | * algorithm.
|
168 | * @since v0.1.90
|
169 | * @param [noDelay=true]
|
170 | * @return The socket itself.
|
171 | */
|
172 | setNoDelay(noDelay?: boolean): this;
|
173 | /**
|
174 | * Enable/disable keep-alive functionality, and optionally set the initial
|
175 | * delay before the first keepalive probe is sent on an idle socket.
|
176 | *
|
177 | * Set `initialDelay` (in milliseconds) to set the delay between the last
|
178 | * data packet received and the first keepalive probe. Setting `0` for`initialDelay` will leave the value unchanged from the default
|
179 | * (or previous) setting.
|
180 | *
|
181 | * Enabling the keep-alive functionality will set the following socket options:
|
182 | *
|
183 | * * `SO_KEEPALIVE=1`
|
184 | * * `TCP_KEEPIDLE=initialDelay`
|
185 | * * `TCP_KEEPCNT=10`
|
186 | * * `TCP_KEEPINTVL=1`
|
187 | * @since v0.1.92
|
188 | * @param [enable=false]
|
189 | * @param [initialDelay=0]
|
190 | * @return The socket itself.
|
191 | */
|
192 | setKeepAlive(enable?: boolean, initialDelay?: number): this;
|
193 | /**
|
194 | * Returns the bound `address`, the address `family` name and `port` of the
|
195 | * socket as reported by the operating system:`{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`
|
196 | * @since v0.1.90
|
197 | */
|
198 | address(): AddressInfo | {};
|
199 | /**
|
200 | * Calling `unref()` on a socket will allow the program to exit if this is the only
|
201 | * active socket in the event system. If the socket is already `unref`ed calling`unref()` again will have no effect.
|
202 | * @since v0.9.1
|
203 | * @return The socket itself.
|
204 | */
|
205 | unref(): this;
|
206 | /**
|
207 | * 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).
|
208 | * If the socket is `ref`ed calling `ref` again will have no effect.
|
209 | * @since v0.9.1
|
210 | * @return The socket itself.
|
211 | */
|
212 | ref(): this;
|
213 | /**
|
214 | * This property shows the number of characters buffered for writing. The buffer
|
215 | * may contain strings whose length after encoding is not yet known. So this number
|
216 | * is only an approximation of the number of bytes in the buffer.
|
217 | *
|
218 | * `net.Socket` has the property that `socket.write()` always works. This is to
|
219 | * help users get up and running quickly. The computer cannot always keep up
|
220 | * with the amount of data that is written to a socket. The network connection
|
221 | * simply might be too slow. Node.js will internally queue up the data written to a
|
222 | * socket and send it out over the wire when it is possible.
|
223 | *
|
224 | * The consequence of this internal buffering is that memory may grow.
|
225 | * Users who experience large or growing `bufferSize` should attempt to
|
226 | * "throttle" the data flows in their program with `socket.pause()` and `socket.resume()`.
|
227 | * @since v0.3.8
|
228 | * @deprecated Since v14.6.0 - Use `writableLength` instead.
|
229 | */
|
230 | readonly bufferSize: number;
|
231 | /**
|
232 | * The amount of received bytes.
|
233 | * @since v0.5.3
|
234 | */
|
235 | readonly bytesRead: number;
|
236 | /**
|
237 | * The amount of bytes sent.
|
238 | * @since v0.5.3
|
239 | */
|
240 | readonly bytesWritten: number;
|
241 | /**
|
242 | * If `true`,`socket.connect(options[, connectListener])` was
|
243 | * called and has not yet finished. It will stay `true` until the socket becomes
|
244 | * connected, then it is set to `false` and the `'connect'` event is emitted. Note
|
245 | * that the `socket.connect(options[, connectListener])` callback is a listener for the `'connect'` event.
|
246 | * @since v6.1.0
|
247 | */
|
248 | readonly connecting: boolean;
|
249 | /**
|
250 | * See `writable.destroyed` for further details.
|
251 | */
|
252 | readonly destroyed: boolean;
|
253 | /**
|
254 | * The string representation of the local IP address the remote client is
|
255 | * connecting on. For example, in a server listening on `'0.0.0.0'`, if a client
|
256 | * connects on `'192.168.1.1'`, the value of `socket.localAddress` would be`'192.168.1.1'`.
|
257 | * @since v0.9.6
|
258 | */
|
259 | readonly localAddress?: string;
|
260 | /**
|
261 | * The numeric representation of the local port. For example, `80` or `21`.
|
262 | * @since v0.9.6
|
263 | */
|
264 | readonly localPort?: number;
|
265 | /**
|
266 | * The string representation of the remote IP address. For example,`'74.125.127.100'` or `'2001:4860:a005::68'`. Value may be `undefined` if
|
267 | * the socket is destroyed (for example, if the client disconnected).
|
268 | * @since v0.5.10
|
269 | */
|
270 | readonly remoteAddress?: string | undefined;
|
271 | /**
|
272 | * The string representation of the remote IP family. `'IPv4'` or `'IPv6'`.
|
273 | * @since v0.11.14
|
274 | */
|
275 | readonly remoteFamily?: string | undefined;
|
276 | /**
|
277 | * The numeric representation of the remote port. For example, `80` or `21`.
|
278 | * @since v0.5.10
|
279 | */
|
280 | readonly remotePort?: number | undefined;
|
281 | /**
|
282 | * Half-closes the socket. i.e., it sends a FIN packet. It is possible the
|
283 | * server will still send some data.
|
284 | *
|
285 | * See `writable.end()` for further details.
|
286 | * @since v0.1.90
|
287 | * @param [encoding='utf8'] Only used when data is `string`.
|
288 | * @param callback Optional callback for when the socket is finished.
|
289 | * @return The socket itself.
|
290 | */
|
291 | end(callback?: () => void): this;
|
292 | end(buffer: Uint8Array | string, callback?: () => void): this;
|
293 | end(str: Uint8Array | string, encoding?: BufferEncoding, callback?: () => void): this;
|
294 | /**
|
295 | * events.EventEmitter
|
296 | * 1. close
|
297 | * 2. connect
|
298 | * 3. data
|
299 | * 4. drain
|
300 | * 5. end
|
301 | * 6. error
|
302 | * 7. lookup
|
303 | * 8. timeout
|
304 | */
|
305 | addListener(event: string, listener: (...args: any[]) => void): this;
|
306 | addListener(event: 'close', listener: (hadError: boolean) => void): this;
|
307 | addListener(event: 'connect', listener: () => void): this;
|
308 | addListener(event: 'data', listener: (data: Buffer) => void): this;
|
309 | addListener(event: 'drain', listener: () => void): this;
|
310 | addListener(event: 'end', listener: () => void): this;
|
311 | addListener(event: 'error', listener: (err: Error) => void): this;
|
312 | addListener(event: 'lookup', listener: (err: Error, address: string, family: string | number, host: string) => void): this;
|
313 | addListener(event: 'ready', listener: () => void): this;
|
314 | addListener(event: 'timeout', listener: () => void): this;
|
315 | emit(event: string | symbol, ...args: any[]): boolean;
|
316 | emit(event: 'close', hadError: boolean): boolean;
|
317 | emit(event: 'connect'): boolean;
|
318 | emit(event: 'data', data: Buffer): boolean;
|
319 | emit(event: 'drain'): boolean;
|
320 | emit(event: 'end'): boolean;
|
321 | emit(event: 'error', err: Error): boolean;
|
322 | emit(event: 'lookup', err: Error, address: string, family: string | number, host: string): boolean;
|
323 | emit(event: 'ready'): boolean;
|
324 | emit(event: 'timeout'): boolean;
|
325 | on(event: string, listener: (...args: any[]) => void): this;
|
326 | on(event: 'close', listener: (hadError: boolean) => void): this;
|
327 | on(event: 'connect', listener: () => void): this;
|
328 | on(event: 'data', listener: (data: Buffer) => void): this;
|
329 | on(event: 'drain', listener: () => void): this;
|
330 | on(event: 'end', listener: () => void): this;
|
331 | on(event: 'error', listener: (err: Error) => void): this;
|
332 | on(event: 'lookup', listener: (err: Error, address: string, family: string | number, host: string) => void): this;
|
333 | on(event: 'ready', listener: () => void): this;
|
334 | on(event: 'timeout', listener: () => void): this;
|
335 | once(event: string, listener: (...args: any[]) => void): this;
|
336 | once(event: 'close', listener: (hadError: boolean) => void): this;
|
337 | once(event: 'connect', listener: () => void): this;
|
338 | once(event: 'data', listener: (data: Buffer) => void): this;
|
339 | once(event: 'drain', listener: () => void): this;
|
340 | once(event: 'end', listener: () => void): this;
|
341 | once(event: 'error', listener: (err: Error) => void): this;
|
342 | once(event: 'lookup', listener: (err: Error, address: string, family: string | number, host: string) => void): this;
|
343 | once(event: 'ready', listener: () => void): this;
|
344 | once(event: 'timeout', listener: () => void): this;
|
345 | prependListener(event: string, listener: (...args: any[]) => void): this;
|
346 | prependListener(event: 'close', listener: (hadError: boolean) => void): this;
|
347 | prependListener(event: 'connect', listener: () => void): this;
|
348 | prependListener(event: 'data', listener: (data: Buffer) => void): this;
|
349 | prependListener(event: 'drain', listener: () => void): this;
|
350 | prependListener(event: 'end', listener: () => void): this;
|
351 | prependListener(event: 'error', listener: (err: Error) => void): this;
|
352 | prependListener(event: 'lookup', listener: (err: Error, address: string, family: string | number, host: string) => void): this;
|
353 | prependListener(event: 'ready', listener: () => void): this;
|
354 | prependListener(event: 'timeout', listener: () => void): this;
|
355 | prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
356 | prependOnceListener(event: 'close', listener: (hadError: boolean) => void): this;
|
357 | prependOnceListener(event: 'connect', listener: () => void): this;
|
358 | prependOnceListener(event: 'data', listener: (data: Buffer) => void): this;
|
359 | prependOnceListener(event: 'drain', listener: () => void): this;
|
360 | prependOnceListener(event: 'end', listener: () => void): this;
|
361 | prependOnceListener(event: 'error', listener: (err: Error) => void): this;
|
362 | prependOnceListener(event: 'lookup', listener: (err: Error, address: string, family: string | number, host: string) => void): this;
|
363 | prependOnceListener(event: 'ready', listener: () => void): this;
|
364 | prependOnceListener(event: 'timeout', listener: () => void): this;
|
365 | }
|
366 | interface ListenOptions extends Abortable {
|
367 | port?: number | undefined;
|
368 | host?: string | undefined;
|
369 | backlog?: number | undefined;
|
370 | path?: string | undefined;
|
371 | exclusive?: boolean | undefined;
|
372 | readableAll?: boolean | undefined;
|
373 | writableAll?: boolean | undefined;
|
374 | /**
|
375 | * @default false
|
376 | */
|
377 | ipv6Only?: boolean | undefined;
|
378 | }
|
379 | interface ServerOpts {
|
380 | /**
|
381 | * Indicates whether half-opened TCP connections are allowed.
|
382 | * @default false
|
383 | */
|
384 | allowHalfOpen?: boolean | undefined;
|
385 | /**
|
386 | * Indicates whether the socket should be paused on incoming connections.
|
387 | * @default false
|
388 | */
|
389 | pauseOnConnect?: boolean | undefined;
|
390 | }
|
391 | /**
|
392 | * This class is used to create a TCP or `IPC` server.
|
393 | * @since v0.1.90
|
394 | */
|
395 | class Server extends EventEmitter {
|
396 | constructor(connectionListener?: (socket: Socket) => void);
|
397 | constructor(options?: ServerOpts, connectionListener?: (socket: Socket) => void);
|
398 | /**
|
399 | * Start a server listening for connections. A `net.Server` can be a TCP or
|
400 | * an `IPC` server depending on what it listens to.
|
401 | *
|
402 | * Possible signatures:
|
403 | *
|
404 | * * `server.listen(handle[, backlog][, callback])`
|
405 | * * `server.listen(options[, callback])`
|
406 | * * `server.listen(path[, backlog][, callback])` for `IPC` servers
|
407 | * * `server.listen([port[, host[, backlog]]][, callback])` for TCP servers
|
408 | *
|
409 | * 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'`
|
410 | * event.
|
411 | *
|
412 | * All `listen()` methods can take a `backlog` parameter to specify the maximum
|
413 | * length of the queue of pending connections. The actual length will be determined
|
414 | * 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).
|
415 | *
|
416 | * All {@link Socket} are set to `SO_REUSEADDR` (see [`socket(7)`](https:
|
417 | * details).
|
418 | *
|
419 | * The `server.listen()` method can be called again if and only if there was an
|
420 | * error during the first `server.listen()` call or `server.close()` has been
|
421 | * called. Otherwise, an `ERR_SERVER_ALREADY_LISTEN` error will be thrown.
|
422 | *
|
423 | * One of the most common errors raised when listening is `EADDRINUSE`.
|
424 | * This happens when another server is already listening on the requested`port`/`path`/`handle`. One way to handle this would be to retry
|
425 | * after a certain amount of time:
|
426 | *
|
427 | * ```js
|
428 | * server.on('error', (e) => {
|
429 | * if (e.code === 'EADDRINUSE') {
|
430 | * console.log('Address in use, retrying...');
|
431 | * setTimeout(() => {
|
432 | * server.close();
|
433 | * server.listen(PORT, HOST);
|
434 | * }, 1000);
|
435 | * }
|
436 | * });
|
437 | * ```
|
438 | */
|
439 | listen(port?: number, hostname?: string, backlog?: number, listeningListener?: () => void): this;
|
440 | listen(port?: number, hostname?: string, listeningListener?: () => void): this;
|
441 | listen(port?: number, backlog?: number, listeningListener?: () => void): this;
|
442 | listen(port?: number, listeningListener?: () => void): this;
|
443 | listen(path: string, backlog?: number, listeningListener?: () => void): this;
|
444 | listen(path: string, listeningListener?: () => void): this;
|
445 | listen(options: ListenOptions, listeningListener?: () => void): this;
|
446 | listen(handle: any, backlog?: number, listeningListener?: () => void): this;
|
447 | listen(handle: any, listeningListener?: () => void): this;
|
448 | |
449 |
|
450 |
|
451 |
|
452 |
|
453 |
|
454 |
|
455 |
|
456 |
|
457 |
|
458 | close(callback?: (err?: Error) => void): this;
|
459 | |
460 |
|
461 |
|
462 |
|
463 |
|
464 |
|
465 |
|
466 |
|
467 |
|
468 |
|
469 |
|
470 |
|
471 |
|
472 |
|
473 |
|
474 |
|
475 |
|
476 |
|
477 |
|
478 |
|
479 |
|
480 |
|
481 |
|
482 |
|
483 |
|
484 |
|
485 | address(): AddressInfo | string | null;
|
486 | |
487 |
|
488 |
|
489 |
|
490 |
|
491 |
|
492 |
|
493 | getConnections(cb: (error: Error | null, count: number) => void): void;
|
494 | |
495 |
|
496 |
|
497 |
|
498 |
|
499 | ref(): this;
|
500 | |
501 |
|
502 |
|
503 |
|
504 |
|
505 | unref(): this;
|
506 | |
507 |
|
508 |
|
509 |
|
510 |
|
511 |
|
512 |
|
513 |
|
514 | maxConnections: number;
|
515 | connections: number;
|
516 | |
517 |
|
518 |
|
519 |
|
520 | listening: boolean;
|
521 | |
522 |
|
523 |
|
524 |
|
525 |
|
526 |
|
527 |
|
528 | addListener(event: string, listener: (...args: any[]) => void): this;
|
529 | addListener(event: 'close', listener: () => void): this;
|
530 | addListener(event: 'connection', listener: (socket: Socket) => void): this;
|
531 | addListener(event: 'error', listener: (err: Error) => void): this;
|
532 | addListener(event: 'listening', listener: () => void): this;
|
533 | emit(event: string | symbol, ...args: any[]): boolean;
|
534 | emit(event: 'close'): boolean;
|
535 | emit(event: 'connection', socket: Socket): boolean;
|
536 | emit(event: 'error', err: Error): boolean;
|
537 | emit(event: 'listening'): boolean;
|
538 | on(event: string, listener: (...args: any[]) => void): this;
|
539 | on(event: 'close', listener: () => void): this;
|
540 | on(event: 'connection', listener: (socket: Socket) => void): this;
|
541 | on(event: 'error', listener: (err: Error) => void): this;
|
542 | on(event: 'listening', listener: () => void): this;
|
543 | once(event: string, listener: (...args: any[]) => void): this;
|
544 | once(event: 'close', listener: () => void): this;
|
545 | once(event: 'connection', listener: (socket: Socket) => void): this;
|
546 | once(event: 'error', listener: (err: Error) => void): this;
|
547 | once(event: 'listening', listener: () => void): this;
|
548 | prependListener(event: string, listener: (...args: any[]) => void): this;
|
549 | prependListener(event: 'close', listener: () => void): this;
|
550 | prependListener(event: 'connection', listener: (socket: Socket) => void): this;
|
551 | prependListener(event: 'error', listener: (err: Error) => void): this;
|
552 | prependListener(event: 'listening', listener: () => void): this;
|
553 | prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
554 | prependOnceListener(event: 'close', listener: () => void): this;
|
555 | prependOnceListener(event: 'connection', listener: (socket: Socket) => void): this;
|
556 | prependOnceListener(event: 'error', listener: (err: Error) => void): this;
|
557 | prependOnceListener(event: 'listening', listener: () => void): this;
|
558 | }
|
559 | type IPVersion = 'ipv4' | 'ipv6';
|
560 | |
561 |
|
562 |
|
563 |
|
564 |
|
565 |
|
566 | class BlockList {
|
567 | |
568 |
|
569 |
|
570 |
|
571 |
|
572 |
|
573 | addAddress(address: string, type?: IPVersion): void;
|
574 | addAddress(address: SocketAddress): void;
|
575 | |
576 |
|
577 |
|
578 |
|
579 |
|
580 |
|
581 |
|
582 | addRange(start: string, end: string, type?: IPVersion): void;
|
583 | addRange(start: SocketAddress, end: SocketAddress): void;
|
584 | |
585 |
|
586 |
|
587 |
|
588 |
|
589 |
|
590 |
|
591 | addSubnet(net: SocketAddress, prefix: number): void;
|
592 | addSubnet(net: string, prefix: number, type?: IPVersion): void;
|
593 | |
594 |
|
595 |
|
596 |
|
597 |
|
598 |
|
599 |
|
600 |
|
601 |
|
602 |
|
603 |
|
604 |
|
605 |
|
606 |
|
607 |
|
608 |
|
609 |
|
610 |
|
611 |
|
612 |
|
613 |
|
614 | check(address: SocketAddress): boolean;
|
615 | check(address: string, type?: IPVersion): boolean;
|
616 | }
|
617 | interface TcpNetConnectOpts extends TcpSocketConnectOpts, SocketConstructorOpts {
|
618 | timeout?: number | undefined;
|
619 | }
|
620 | interface IpcNetConnectOpts extends IpcSocketConnectOpts, SocketConstructorOpts {
|
621 | timeout?: number | undefined;
|
622 | }
|
623 | type NetConnectOpts = TcpNetConnectOpts | IpcNetConnectOpts;
|
624 | |
625 |
|
626 |
|
627 |
|
628 |
|
629 |
|
630 |
|
631 |
|
632 |
|
633 |
|
634 |
|
635 |
|
636 |
|
637 |
|
638 |
|
639 |
|
640 |
|
641 |
|
642 |
|
643 |
|
644 |
|
645 |
|
646 |
|
647 |
|
648 |
|
649 |
|
650 |
|
651 |
|
652 |
|
653 |
|
654 |
|
655 |
|
656 |
|
657 |
|
658 |
|
659 |
|
660 |
|
661 |
|
662 |
|
663 |
|
664 |
|
665 |
|
666 |
|
667 |
|
668 |
|
669 |
|
670 |
|
671 |
|
672 |
|
673 |
|
674 |
|
675 |
|
676 |
|
677 |
|
678 |
|
679 |
|
680 |
|
681 |
|
682 |
|
683 |
|
684 |
|
685 | function createServer(connectionListener?: (socket: Socket) => void): Server;
|
686 | function createServer(options?: ServerOpts, connectionListener?: (socket: Socket) => void): Server;
|
687 | |
688 |
|
689 |
|
690 |
|
691 |
|
692 |
|
693 |
|
694 |
|
695 |
|
696 | function connect(options: NetConnectOpts, connectionListener?: () => void): Socket;
|
697 | function connect(port: number, host?: string, connectionListener?: () => void): Socket;
|
698 | function connect(path: string, connectionListener?: () => void): Socket;
|
699 | |
700 |
|
701 |
|
702 |
|
703 |
|
704 |
|
705 |
|
706 |
|
707 |
|
708 |
|
709 |
|
710 |
|
711 |
|
712 |
|
713 |
|
714 |
|
715 |
|
716 | function createConnection(options: NetConnectOpts, connectionListener?: () => void): Socket;
|
717 | function createConnection(port: number, host?: string, connectionListener?: () => void): Socket;
|
718 | function createConnection(path: string, connectionListener?: () => void): Socket;
|
719 | |
720 |
|
721 |
|
722 |
|
723 |
|
724 |
|
725 | function isIP(input: string): number;
|
726 | |
727 |
|
728 |
|
729 |
|
730 | function isIPv4(input: string): boolean;
|
731 | |
732 |
|
733 |
|
734 |
|
735 | function isIPv6(input: string): boolean;
|
736 | interface SocketAddressInitOptions {
|
737 | |
738 |
|
739 |
|
740 |
|
741 | address?: string | undefined;
|
742 | |
743 |
|
744 |
|
745 | family?: IPVersion | undefined;
|
746 | |
747 |
|
748 |
|
749 |
|
750 | flowlabel?: number | undefined;
|
751 | |
752 |
|
753 |
|
754 |
|
755 | port?: number | undefined;
|
756 | }
|
757 | |
758 |
|
759 |
|
760 | class SocketAddress {
|
761 | constructor(options: SocketAddressInitOptions);
|
762 | |
763 |
|
764 |
|
765 |
|
766 | readonly address: string;
|
767 | |
768 |
|
769 |
|
770 |
|
771 | readonly family: IPVersion;
|
772 | |
773 |
|
774 |
|
775 | readonly port: number;
|
776 | |
777 |
|
778 |
|
779 | readonly flowlabel: number;
|
780 | }
|
781 | }
|
782 | declare module 'node:net' {
|
783 | export * from 'net';
|
784 | }
|
785 |
|
\ | No newline at end of file |