m06_task3.js 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.idea/.name +1 -0
- package/.idea/inspectionProfiles/Project_Default.xml +10 -0
- package/.idea/jsLibraryMappings.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/node_lab_6.iml +12 -0
- package/06_task2.html +73 -0
- package/06_task2.js +52 -0
- package/06_task3.js +3 -0
- package/06_task4.js +3 -0
- package/m06_task3.js +28 -0
- package/package/index.js +28 -0
- package/package/node_modules/.package-lock.json +31 -0
- package/package/node_modules/@types/node/LICENSE +21 -0
- package/package/node_modules/@types/node/README.md +16 -0
- package/package/node_modules/@types/node/assert/strict.d.ts +8 -0
- package/package/node_modules/@types/node/assert.d.ts +961 -0
- package/package/node_modules/@types/node/async_hooks.d.ts +501 -0
- package/package/node_modules/@types/node/buffer.d.ts +2258 -0
- package/package/node_modules/@types/node/child_process.d.ts +1369 -0
- package/package/node_modules/@types/node/cluster.d.ts +410 -0
- package/package/node_modules/@types/node/console.d.ts +412 -0
- package/package/node_modules/@types/node/constants.d.ts +18 -0
- package/package/node_modules/@types/node/crypto.d.ts +3964 -0
- package/package/node_modules/@types/node/dgram.d.ts +545 -0
- package/package/node_modules/@types/node/diagnostics_channel.d.ts +153 -0
- package/package/node_modules/@types/node/dns/promises.d.ts +370 -0
- package/package/node_modules/@types/node/dns.d.ts +659 -0
- package/package/node_modules/@types/node/dom-events.d.ts +126 -0
- package/package/node_modules/@types/node/domain.d.ts +170 -0
- package/package/node_modules/@types/node/events.d.ts +678 -0
- package/package/node_modules/@types/node/fs/promises.d.ts +1138 -0
- package/package/node_modules/@types/node/fs.d.ts +3872 -0
- package/package/node_modules/@types/node/globals.d.ts +300 -0
- package/package/node_modules/@types/node/globals.global.d.ts +1 -0
- package/package/node_modules/@types/node/http.d.ts +1614 -0
- package/package/node_modules/@types/node/http2.d.ts +2134 -0
- package/package/node_modules/@types/node/https.d.ts +541 -0
- package/package/node_modules/@types/node/index.d.ts +133 -0
- package/package/node_modules/@types/node/inspector.d.ts +2741 -0
- package/package/node_modules/@types/node/module.d.ts +114 -0
- package/package/node_modules/@types/node/net.d.ts +869 -0
- package/package/node_modules/@types/node/os.d.ts +466 -0
- package/package/node_modules/@types/node/package.json +232 -0
- package/package/node_modules/@types/node/path.d.ts +191 -0
- package/package/node_modules/@types/node/perf_hooks.d.ts +625 -0
- package/package/node_modules/@types/node/process.d.ts +1482 -0
- package/package/node_modules/@types/node/punycode.d.ts +117 -0
- package/package/node_modules/@types/node/querystring.d.ts +131 -0
- package/package/node_modules/@types/node/readline/promises.d.ts +143 -0
- package/package/node_modules/@types/node/readline.d.ts +653 -0
- package/package/node_modules/@types/node/repl.d.ts +424 -0
- package/package/node_modules/@types/node/stream/consumers.d.ts +12 -0
- package/package/node_modules/@types/node/stream/promises.d.ts +42 -0
- package/package/node_modules/@types/node/stream/web.d.ts +330 -0
- package/package/node_modules/@types/node/stream.d.ts +1340 -0
- package/package/node_modules/@types/node/string_decoder.d.ts +67 -0
- package/package/node_modules/@types/node/test.d.ts +314 -0
- package/package/node_modules/@types/node/timers/promises.d.ts +68 -0
- package/package/node_modules/@types/node/timers.d.ts +94 -0
- package/package/node_modules/@types/node/tls.d.ts +1028 -0
- package/package/node_modules/@types/node/trace_events.d.ts +171 -0
- package/package/node_modules/@types/node/ts4.8/assert/strict.d.ts +8 -0
- package/package/node_modules/@types/node/ts4.8/assert.d.ts +961 -0
- package/package/node_modules/@types/node/ts4.8/async_hooks.d.ts +501 -0
- package/package/node_modules/@types/node/ts4.8/buffer.d.ts +2259 -0
- package/package/node_modules/@types/node/ts4.8/child_process.d.ts +1369 -0
- package/package/node_modules/@types/node/ts4.8/cluster.d.ts +410 -0
- package/package/node_modules/@types/node/ts4.8/console.d.ts +412 -0
- package/package/node_modules/@types/node/ts4.8/constants.d.ts +18 -0
- package/package/node_modules/@types/node/ts4.8/crypto.d.ts +3964 -0
- package/package/node_modules/@types/node/ts4.8/dgram.d.ts +545 -0
- package/package/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts +153 -0
- package/package/node_modules/@types/node/ts4.8/dns/promises.d.ts +370 -0
- package/package/node_modules/@types/node/ts4.8/dns.d.ts +659 -0
- package/package/node_modules/@types/node/ts4.8/dom-events.d.ts +126 -0
- package/package/node_modules/@types/node/ts4.8/domain.d.ts +170 -0
- package/package/node_modules/@types/node/ts4.8/events.d.ts +678 -0
- package/package/node_modules/@types/node/ts4.8/fs/promises.d.ts +1138 -0
- package/package/node_modules/@types/node/ts4.8/fs.d.ts +3872 -0
- package/package/node_modules/@types/node/ts4.8/globals.d.ts +294 -0
- package/package/node_modules/@types/node/ts4.8/globals.global.d.ts +1 -0
- package/package/node_modules/@types/node/ts4.8/http.d.ts +1614 -0
- package/package/node_modules/@types/node/ts4.8/http2.d.ts +2134 -0
- package/package/node_modules/@types/node/ts4.8/https.d.ts +541 -0
- package/package/node_modules/@types/node/ts4.8/index.d.ts +88 -0
- package/package/node_modules/@types/node/ts4.8/inspector.d.ts +2741 -0
- package/package/node_modules/@types/node/ts4.8/module.d.ts +114 -0
- package/package/node_modules/@types/node/ts4.8/net.d.ts +869 -0
- package/package/node_modules/@types/node/ts4.8/os.d.ts +466 -0
- package/package/node_modules/@types/node/ts4.8/path.d.ts +191 -0
- package/package/node_modules/@types/node/ts4.8/perf_hooks.d.ts +625 -0
- package/package/node_modules/@types/node/ts4.8/process.d.ts +1482 -0
- package/package/node_modules/@types/node/ts4.8/punycode.d.ts +117 -0
- package/package/node_modules/@types/node/ts4.8/querystring.d.ts +131 -0
- package/package/node_modules/@types/node/ts4.8/readline/promises.d.ts +143 -0
- package/package/node_modules/@types/node/ts4.8/readline.d.ts +653 -0
- package/package/node_modules/@types/node/ts4.8/repl.d.ts +424 -0
- package/package/node_modules/@types/node/ts4.8/stream/consumers.d.ts +12 -0
- package/package/node_modules/@types/node/ts4.8/stream/promises.d.ts +42 -0
- package/package/node_modules/@types/node/ts4.8/stream/web.d.ts +330 -0
- package/package/node_modules/@types/node/ts4.8/stream.d.ts +1340 -0
- package/package/node_modules/@types/node/ts4.8/string_decoder.d.ts +67 -0
- package/package/node_modules/@types/node/ts4.8/test.d.ts +314 -0
- package/package/node_modules/@types/node/ts4.8/timers/promises.d.ts +68 -0
- package/package/node_modules/@types/node/ts4.8/timers.d.ts +94 -0
- package/package/node_modules/@types/node/ts4.8/tls.d.ts +1028 -0
- package/package/node_modules/@types/node/ts4.8/trace_events.d.ts +171 -0
- package/package/node_modules/@types/node/ts4.8/tty.d.ts +206 -0
- package/package/node_modules/@types/node/ts4.8/url.d.ts +897 -0
- package/package/node_modules/@types/node/ts4.8/util.d.ts +1850 -0
- package/package/node_modules/@types/node/ts4.8/v8.d.ts +396 -0
- package/package/node_modules/@types/node/ts4.8/vm.d.ts +509 -0
- package/package/node_modules/@types/node/ts4.8/wasi.d.ts +158 -0
- package/package/node_modules/@types/node/ts4.8/worker_threads.d.ts +689 -0
- package/package/node_modules/@types/node/ts4.8/zlib.d.ts +517 -0
- package/package/node_modules/@types/node/tty.d.ts +206 -0
- package/package/node_modules/@types/node/url.d.ts +897 -0
- package/package/node_modules/@types/node/util.d.ts +1850 -0
- package/package/node_modules/@types/node/v8.d.ts +396 -0
- package/package/node_modules/@types/node/vm.d.ts +509 -0
- package/package/node_modules/@types/node/wasi.d.ts +158 -0
- package/package/node_modules/@types/node/worker_threads.d.ts +689 -0
- package/package/node_modules/@types/node/zlib.d.ts +517 -0
- package/package/node_modules/@types/nodemailer/LICENSE +21 -0
- package/package/node_modules/@types/nodemailer/README.md +16 -0
- package/package/node_modules/@types/nodemailer/index.d.ts +83 -0
- package/package/node_modules/@types/nodemailer/lib/addressparser/index.d.ts +31 -0
- package/package/node_modules/@types/nodemailer/lib/base64/index.d.ts +22 -0
- package/package/node_modules/@types/nodemailer/lib/dkim/index.d.ts +45 -0
- package/package/node_modules/@types/nodemailer/lib/dkim/message-parser.d.ts +75 -0
- package/package/node_modules/@types/nodemailer/lib/dkim/relaxed-body.d.ts +75 -0
- package/package/node_modules/@types/nodemailer/lib/dkim/sign.d.ts +11 -0
- package/package/node_modules/@types/nodemailer/lib/fetch/cookies.d.ts +54 -0
- package/package/node_modules/@types/nodemailer/lib/fetch/index.d.ts +38 -0
- package/package/node_modules/@types/nodemailer/lib/json-transport/index.d.ts +50 -0
- package/package/node_modules/@types/nodemailer/lib/mail-composer/index.d.ts +25 -0
- package/package/node_modules/@types/nodemailer/lib/mailer/index.d.ts +230 -0
- package/package/node_modules/@types/nodemailer/lib/mailer/mail-message.d.ts +28 -0
- package/package/node_modules/@types/nodemailer/lib/mime-funcs/index.d.ts +87 -0
- package/package/node_modules/@types/nodemailer/lib/mime-funcs/mime-types.d.ts +2 -0
- package/package/node_modules/@types/nodemailer/lib/mime-node/index.d.ts +137 -0
- package/package/node_modules/@types/nodemailer/lib/mime-node/last-newline.d.ts +9 -0
- package/package/node_modules/@types/nodemailer/lib/qp/index.d.ts +23 -0
- package/package/node_modules/@types/nodemailer/lib/sendmail-transport/index.d.ts +53 -0
- package/package/node_modules/@types/nodemailer/lib/sendmail-transport/le-unix.d.ts +7 -0
- package/package/node_modules/@types/nodemailer/lib/sendmail-transport/le-windows.d.ts +7 -0
- package/package/node_modules/@types/nodemailer/lib/ses-transport/index.d.ts +136 -0
- package/package/node_modules/@types/nodemailer/lib/shared/index.d.ts +51 -0
- package/package/node_modules/@types/nodemailer/lib/smtp-connection/data-stream.d.ts +11 -0
- package/package/node_modules/@types/nodemailer/lib/smtp-connection/http-proxy-client.d.ts +11 -0
- package/package/node_modules/@types/nodemailer/lib/smtp-connection/index.d.ts +254 -0
- package/package/node_modules/@types/nodemailer/lib/smtp-pool/index.d.ts +90 -0
- package/package/node_modules/@types/nodemailer/lib/smtp-pool/pool-resource.d.ts +66 -0
- package/package/node_modules/@types/nodemailer/lib/smtp-transport/index.d.ts +115 -0
- package/package/node_modules/@types/nodemailer/lib/stream-transport/index.d.ts +56 -0
- package/package/node_modules/@types/nodemailer/lib/well-known/index.d.ts +6 -0
- package/package/node_modules/@types/nodemailer/lib/xoauth2/index.d.ts +110 -0
- package/package/node_modules/@types/nodemailer/package.json +37 -0
- package/package/node_modules/nodemailer/.gitattributes +6 -0
- package/package/node_modules/nodemailer/.prettierrc.js +8 -0
- package/package/node_modules/nodemailer/CHANGELOG.md +715 -0
- package/package/node_modules/nodemailer/CODE_OF_CONDUCT.md +76 -0
- package/package/node_modules/nodemailer/CONTRIBUTING.md +67 -0
- package/package/node_modules/nodemailer/LICENSE +16 -0
- package/package/node_modules/nodemailer/README.md +93 -0
- package/package/node_modules/nodemailer/SECURITY.txt +22 -0
- package/package/node_modules/nodemailer/lib/addressparser/index.js +313 -0
- package/package/node_modules/nodemailer/lib/base64/index.js +142 -0
- package/package/node_modules/nodemailer/lib/dkim/index.js +251 -0
- package/package/node_modules/nodemailer/lib/dkim/message-parser.js +155 -0
- package/package/node_modules/nodemailer/lib/dkim/relaxed-body.js +154 -0
- package/package/node_modules/nodemailer/lib/dkim/sign.js +117 -0
- package/package/node_modules/nodemailer/lib/fetch/cookies.js +281 -0
- package/package/node_modules/nodemailer/lib/fetch/index.js +269 -0
- package/package/node_modules/nodemailer/lib/json-transport/index.js +82 -0
- package/package/node_modules/nodemailer/lib/mail-composer/index.js +558 -0
- package/package/node_modules/nodemailer/lib/mailer/index.js +427 -0
- package/package/node_modules/nodemailer/lib/mailer/mail-message.js +315 -0
- package/package/node_modules/nodemailer/lib/mime-funcs/index.js +619 -0
- package/package/node_modules/nodemailer/lib/mime-funcs/mime-types.js +2102 -0
- package/package/node_modules/nodemailer/lib/mime-node/index.js +1290 -0
- package/package/node_modules/nodemailer/lib/mime-node/last-newline.js +33 -0
- package/package/node_modules/nodemailer/lib/mime-node/le-unix.js +43 -0
- package/package/node_modules/nodemailer/lib/mime-node/le-windows.js +52 -0
- package/package/node_modules/nodemailer/lib/nodemailer.js +143 -0
- package/package/node_modules/nodemailer/lib/qp/index.js +219 -0
- package/package/node_modules/nodemailer/lib/sendmail-transport/index.js +210 -0
- package/package/node_modules/nodemailer/lib/ses-transport/index.js +349 -0
- package/package/node_modules/nodemailer/lib/shared/index.js +639 -0
- package/package/node_modules/nodemailer/lib/smtp-connection/data-stream.js +108 -0
- package/package/node_modules/nodemailer/lib/smtp-connection/http-proxy-client.js +143 -0
- package/package/node_modules/nodemailer/lib/smtp-connection/index.js +1786 -0
- package/package/node_modules/nodemailer/lib/smtp-pool/index.js +648 -0
- package/package/node_modules/nodemailer/lib/smtp-pool/pool-resource.js +253 -0
- package/package/node_modules/nodemailer/lib/smtp-transport/index.js +416 -0
- package/package/node_modules/nodemailer/lib/stream-transport/index.js +135 -0
- package/package/node_modules/nodemailer/lib/well-known/index.js +47 -0
- package/package/node_modules/nodemailer/lib/well-known/services.json +286 -0
- package/package/node_modules/nodemailer/lib/xoauth2/index.js +376 -0
- package/package/node_modules/nodemailer/package.json +46 -0
- package/package/node_modules/nodemailer/postinstall.js +101 -0
- package/package/package-lock.json +60 -0
- package/package/package.json +6 -0
- package/package.json +19 -0
@@ -0,0 +1,869 @@
|
|
1
|
+
/**
|
2
|
+
* > Stability: 2 - Stable
|
3
|
+
*
|
4
|
+
* The `net` module provides an asynchronous network API for creating stream-based
|
5
|
+
* TCP or `IPC` servers ({@link createServer}) and clients
|
6
|
+
* ({@link createConnection}).
|
7
|
+
*
|
8
|
+
* It can be accessed using:
|
9
|
+
*
|
10
|
+
* ```js
|
11
|
+
* const net = require('net');
|
12
|
+
* ```
|
13
|
+
* @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/net.js)
|
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
|
+
noDelay?: boolean | undefined;
|
58
|
+
keepAlive?: boolean | undefined;
|
59
|
+
keepAliveInitialDelay?: number | undefined;
|
60
|
+
}
|
61
|
+
interface IpcSocketConnectOpts extends ConnectOpts {
|
62
|
+
path: string;
|
63
|
+
}
|
64
|
+
type SocketConnectOpts = TcpSocketConnectOpts | IpcSocketConnectOpts;
|
65
|
+
type SocketReadyState = 'opening' | 'open' | 'readOnly' | 'writeOnly' | 'closed';
|
66
|
+
/**
|
67
|
+
* This class is an abstraction of a TCP socket or a streaming `IPC` endpoint
|
68
|
+
* (uses named pipes on Windows, and Unix domain sockets otherwise). It is also
|
69
|
+
* an `EventEmitter`.
|
70
|
+
*
|
71
|
+
* A `net.Socket` can be created by the user and used directly to interact with
|
72
|
+
* a server. For example, it is returned by {@link createConnection},
|
73
|
+
* so the user can use it to talk to the server.
|
74
|
+
*
|
75
|
+
* It can also be created by Node.js and passed to the user when a connection
|
76
|
+
* is received. For example, it is passed to the listeners of a `'connection'` event emitted on a {@link Server}, so the user can use
|
77
|
+
* it to interact with the client.
|
78
|
+
* @since v0.3.4
|
79
|
+
*/
|
80
|
+
class Socket extends stream.Duplex {
|
81
|
+
constructor(options?: SocketConstructorOpts);
|
82
|
+
/**
|
83
|
+
* Sends data on the socket. The second parameter specifies the encoding in the
|
84
|
+
* case of a string. It defaults to UTF8 encoding.
|
85
|
+
*
|
86
|
+
* Returns `true` if the entire data was flushed successfully to the kernel
|
87
|
+
* 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.
|
88
|
+
*
|
89
|
+
* The optional `callback` parameter will be executed when the data is finally
|
90
|
+
* written out, which may not be immediately.
|
91
|
+
*
|
92
|
+
* See `Writable` stream `write()` method for more
|
93
|
+
* information.
|
94
|
+
* @since v0.1.90
|
95
|
+
* @param [encoding='utf8'] Only used when data is `string`.
|
96
|
+
*/
|
97
|
+
write(buffer: Uint8Array | string, cb?: (err?: Error) => void): boolean;
|
98
|
+
write(str: Uint8Array | string, encoding?: BufferEncoding, cb?: (err?: Error) => void): boolean;
|
99
|
+
/**
|
100
|
+
* Initiate a connection on a given socket.
|
101
|
+
*
|
102
|
+
* Possible signatures:
|
103
|
+
*
|
104
|
+
* * `socket.connect(options[, connectListener])`
|
105
|
+
* * `socket.connect(path[, connectListener])` for `IPC` connections.
|
106
|
+
* * `socket.connect(port[, host][, connectListener])` for TCP connections.
|
107
|
+
* * Returns: `net.Socket` The socket itself.
|
108
|
+
*
|
109
|
+
* This function is asynchronous. When the connection is established, the `'connect'` event will be emitted. If there is a problem connecting,
|
110
|
+
* instead of a `'connect'` event, an `'error'` event will be emitted with
|
111
|
+
* the error passed to the `'error'` listener.
|
112
|
+
* The last parameter `connectListener`, if supplied, will be added as a listener
|
113
|
+
* for the `'connect'` event **once**.
|
114
|
+
*
|
115
|
+
* This function should only be used for reconnecting a socket after`'close'` has been emitted or otherwise it may lead to undefined
|
116
|
+
* behavior.
|
117
|
+
*/
|
118
|
+
connect(options: SocketConnectOpts, connectionListener?: () => void): this;
|
119
|
+
connect(port: number, host: string, connectionListener?: () => void): this;
|
120
|
+
connect(port: number, connectionListener?: () => void): this;
|
121
|
+
connect(path: string, connectionListener?: () => void): this;
|
122
|
+
/**
|
123
|
+
* Set the encoding for the socket as a `Readable Stream`. See `readable.setEncoding()` for more information.
|
124
|
+
* @since v0.1.90
|
125
|
+
* @return The socket itself.
|
126
|
+
*/
|
127
|
+
setEncoding(encoding?: BufferEncoding): this;
|
128
|
+
/**
|
129
|
+
* Pauses the reading of data. That is, `'data'` events will not be emitted.
|
130
|
+
* Useful to throttle back an upload.
|
131
|
+
* @return The socket itself.
|
132
|
+
*/
|
133
|
+
pause(): this;
|
134
|
+
/**
|
135
|
+
* Close the TCP connection by sending an RST packet and destroy the stream.
|
136
|
+
* If this TCP socket is in connecting status, it will send an RST packet
|
137
|
+
* and destroy this TCP socket once it is connected. Otherwise, it will call
|
138
|
+
* `socket.destroy` with an `ERR_SOCKET_CLOSED` Error. If this is not a TCP socket
|
139
|
+
* (for example, a pipe), calling this method will immediately throw
|
140
|
+
* an `ERR_INVALID_HANDLE_TYPE` Error.
|
141
|
+
* @since v18.3.0
|
142
|
+
* @return The socket itself.
|
143
|
+
*/
|
144
|
+
resetAndDestroy(): this;
|
145
|
+
/**
|
146
|
+
* Resumes reading after a call to `socket.pause()`.
|
147
|
+
* @return The socket itself.
|
148
|
+
*/
|
149
|
+
resume(): this;
|
150
|
+
/**
|
151
|
+
* Sets the socket to timeout after `timeout` milliseconds of inactivity on
|
152
|
+
* the socket. By default `net.Socket` do not have a timeout.
|
153
|
+
*
|
154
|
+
* 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
|
155
|
+
* end the connection.
|
156
|
+
*
|
157
|
+
* ```js
|
158
|
+
* socket.setTimeout(3000);
|
159
|
+
* socket.on('timeout', () => {
|
160
|
+
* console.log('socket timeout');
|
161
|
+
* socket.end();
|
162
|
+
* });
|
163
|
+
* ```
|
164
|
+
*
|
165
|
+
* If `timeout` is 0, then the existing idle timeout is disabled.
|
166
|
+
*
|
167
|
+
* The optional `callback` parameter will be added as a one-time listener for the `'timeout'` event.
|
168
|
+
* @since v0.1.90
|
169
|
+
* @return The socket itself.
|
170
|
+
*/
|
171
|
+
setTimeout(timeout: number, callback?: () => void): this;
|
172
|
+
/**
|
173
|
+
* Enable/disable the use of Nagle's algorithm.
|
174
|
+
*
|
175
|
+
* When a TCP connection is created, it will have Nagle's algorithm enabled.
|
176
|
+
*
|
177
|
+
* Nagle's algorithm delays data before it is sent via the network. It attempts
|
178
|
+
* to optimize throughput at the expense of latency.
|
179
|
+
*
|
180
|
+
* Passing `true` for `noDelay` or not passing an argument will disable Nagle's
|
181
|
+
* algorithm for the socket. Passing `false` for `noDelay` will enable Nagle's
|
182
|
+
* algorithm.
|
183
|
+
* @since v0.1.90
|
184
|
+
* @param [noDelay=true]
|
185
|
+
* @return The socket itself.
|
186
|
+
*/
|
187
|
+
setNoDelay(noDelay?: boolean): this;
|
188
|
+
/**
|
189
|
+
* Enable/disable keep-alive functionality, and optionally set the initial
|
190
|
+
* delay before the first keepalive probe is sent on an idle socket.
|
191
|
+
*
|
192
|
+
* Set `initialDelay` (in milliseconds) to set the delay between the last
|
193
|
+
* data packet received and the first keepalive probe. Setting `0` for`initialDelay` will leave the value unchanged from the default
|
194
|
+
* (or previous) setting.
|
195
|
+
*
|
196
|
+
* Enabling the keep-alive functionality will set the following socket options:
|
197
|
+
*
|
198
|
+
* * `SO_KEEPALIVE=1`
|
199
|
+
* * `TCP_KEEPIDLE=initialDelay`
|
200
|
+
* * `TCP_KEEPCNT=10`
|
201
|
+
* * `TCP_KEEPINTVL=1`
|
202
|
+
* @since v0.1.92
|
203
|
+
* @param [enable=false]
|
204
|
+
* @param [initialDelay=0]
|
205
|
+
* @return The socket itself.
|
206
|
+
*/
|
207
|
+
setKeepAlive(enable?: boolean, initialDelay?: number): this;
|
208
|
+
/**
|
209
|
+
* Returns the bound `address`, the address `family` name and `port` of the
|
210
|
+
* socket as reported by the operating system:`{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`
|
211
|
+
* @since v0.1.90
|
212
|
+
*/
|
213
|
+
address(): AddressInfo | {};
|
214
|
+
/**
|
215
|
+
* Calling `unref()` on a socket will allow the program to exit if this is the only
|
216
|
+
* active socket in the event system. If the socket is already `unref`ed calling`unref()` again will have no effect.
|
217
|
+
* @since v0.9.1
|
218
|
+
* @return The socket itself.
|
219
|
+
*/
|
220
|
+
unref(): this;
|
221
|
+
/**
|
222
|
+
* 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).
|
223
|
+
* If the socket is `ref`ed calling `ref` again will have no effect.
|
224
|
+
* @since v0.9.1
|
225
|
+
* @return The socket itself.
|
226
|
+
*/
|
227
|
+
ref(): this;
|
228
|
+
/**
|
229
|
+
* This property shows the number of characters buffered for writing. The buffer
|
230
|
+
* may contain strings whose length after encoding is not yet known. So this number
|
231
|
+
* is only an approximation of the number of bytes in the buffer.
|
232
|
+
*
|
233
|
+
* `net.Socket` has the property that `socket.write()` always works. This is to
|
234
|
+
* help users get up and running quickly. The computer cannot always keep up
|
235
|
+
* with the amount of data that is written to a socket. The network connection
|
236
|
+
* simply might be too slow. Node.js will internally queue up the data written to a
|
237
|
+
* socket and send it out over the wire when it is possible.
|
238
|
+
*
|
239
|
+
* The consequence of this internal buffering is that memory may grow.
|
240
|
+
* Users who experience large or growing `bufferSize` should attempt to
|
241
|
+
* "throttle" the data flows in their program with `socket.pause()` and `socket.resume()`.
|
242
|
+
* @since v0.3.8
|
243
|
+
* @deprecated Since v14.6.0 - Use `writableLength` instead.
|
244
|
+
*/
|
245
|
+
readonly bufferSize: number;
|
246
|
+
/**
|
247
|
+
* The amount of received bytes.
|
248
|
+
* @since v0.5.3
|
249
|
+
*/
|
250
|
+
readonly bytesRead: number;
|
251
|
+
/**
|
252
|
+
* The amount of bytes sent.
|
253
|
+
* @since v0.5.3
|
254
|
+
*/
|
255
|
+
readonly bytesWritten: number;
|
256
|
+
/**
|
257
|
+
* If `true`,`socket.connect(options[, connectListener])` was
|
258
|
+
* called and has not yet finished. It will stay `true` until the socket becomes
|
259
|
+
* connected, then it is set to `false` and the `'connect'` event is emitted. Note
|
260
|
+
* that the `socket.connect(options[, connectListener])` callback is a listener for the `'connect'` event.
|
261
|
+
* @since v6.1.0
|
262
|
+
*/
|
263
|
+
readonly connecting: boolean;
|
264
|
+
/**
|
265
|
+
* See `writable.destroyed` for further details.
|
266
|
+
*/
|
267
|
+
readonly destroyed: boolean;
|
268
|
+
/**
|
269
|
+
* The string representation of the local IP address the remote client is
|
270
|
+
* connecting on. For example, in a server listening on `'0.0.0.0'`, if a client
|
271
|
+
* connects on `'192.168.1.1'`, the value of `socket.localAddress` would be`'192.168.1.1'`.
|
272
|
+
* @since v0.9.6
|
273
|
+
*/
|
274
|
+
readonly localAddress?: string;
|
275
|
+
/**
|
276
|
+
* The numeric representation of the local port. For example, `80` or `21`.
|
277
|
+
* @since v0.9.6
|
278
|
+
*/
|
279
|
+
readonly localPort?: number;
|
280
|
+
/**
|
281
|
+
* The string representation of the local IP family. `'IPv4'` or `'IPv6'`.
|
282
|
+
* @since v18.8.0
|
283
|
+
*/
|
284
|
+
readonly localFamily?: string;
|
285
|
+
/**
|
286
|
+
* This property represents the state of the connection as a string.
|
287
|
+
* @see {https://nodejs.org/api/net.html#socketreadystate}
|
288
|
+
* @since v0.5.0
|
289
|
+
*/
|
290
|
+
readonly readyState: SocketReadyState;
|
291
|
+
/**
|
292
|
+
* The string representation of the remote IP address. For example,`'74.125.127.100'` or `'2001:4860:a005::68'`. Value may be `undefined` if
|
293
|
+
* the socket is destroyed (for example, if the client disconnected).
|
294
|
+
* @since v0.5.10
|
295
|
+
*/
|
296
|
+
readonly remoteAddress?: string | undefined;
|
297
|
+
/**
|
298
|
+
* The string representation of the remote IP family. `'IPv4'` or `'IPv6'`.
|
299
|
+
* @since v0.11.14
|
300
|
+
*/
|
301
|
+
readonly remoteFamily?: string | undefined;
|
302
|
+
/**
|
303
|
+
* The numeric representation of the remote port. For example, `80` or `21`.
|
304
|
+
* @since v0.5.10
|
305
|
+
*/
|
306
|
+
readonly remotePort?: number | undefined;
|
307
|
+
/**
|
308
|
+
* The socket timeout in milliseconds as set by socket.setTimeout(). It is undefined if a timeout has not been set.
|
309
|
+
* @since v10.7.0
|
310
|
+
*/
|
311
|
+
readonly timeout?: number | undefined;
|
312
|
+
/**
|
313
|
+
* Half-closes the socket. i.e., it sends a FIN packet. It is possible the
|
314
|
+
* server will still send some data.
|
315
|
+
*
|
316
|
+
* See `writable.end()` for further details.
|
317
|
+
* @since v0.1.90
|
318
|
+
* @param [encoding='utf8'] Only used when data is `string`.
|
319
|
+
* @param callback Optional callback for when the socket is finished.
|
320
|
+
* @return The socket itself.
|
321
|
+
*/
|
322
|
+
end(callback?: () => void): this;
|
323
|
+
end(buffer: Uint8Array | string, callback?: () => void): this;
|
324
|
+
end(str: Uint8Array | string, encoding?: BufferEncoding, callback?: () => void): this;
|
325
|
+
/**
|
326
|
+
* events.EventEmitter
|
327
|
+
* 1. close
|
328
|
+
* 2. connect
|
329
|
+
* 3. data
|
330
|
+
* 4. drain
|
331
|
+
* 5. end
|
332
|
+
* 6. error
|
333
|
+
* 7. lookup
|
334
|
+
* 8. ready
|
335
|
+
* 9. timeout
|
336
|
+
*/
|
337
|
+
addListener(event: string, listener: (...args: any[]) => void): this;
|
338
|
+
addListener(event: 'close', listener: (hadError: boolean) => void): this;
|
339
|
+
addListener(event: 'connect', listener: () => void): this;
|
340
|
+
addListener(event: 'data', listener: (data: Buffer) => void): this;
|
341
|
+
addListener(event: 'drain', listener: () => void): this;
|
342
|
+
addListener(event: 'end', listener: () => void): this;
|
343
|
+
addListener(event: 'error', listener: (err: Error) => void): this;
|
344
|
+
addListener(event: 'lookup', listener: (err: Error, address: string, family: string | number, host: string) => void): this;
|
345
|
+
addListener(event: 'ready', listener: () => void): this;
|
346
|
+
addListener(event: 'timeout', listener: () => void): this;
|
347
|
+
emit(event: string | symbol, ...args: any[]): boolean;
|
348
|
+
emit(event: 'close', hadError: boolean): boolean;
|
349
|
+
emit(event: 'connect'): boolean;
|
350
|
+
emit(event: 'data', data: Buffer): boolean;
|
351
|
+
emit(event: 'drain'): boolean;
|
352
|
+
emit(event: 'end'): boolean;
|
353
|
+
emit(event: 'error', err: Error): boolean;
|
354
|
+
emit(event: 'lookup', err: Error, address: string, family: string | number, host: string): boolean;
|
355
|
+
emit(event: 'ready'): boolean;
|
356
|
+
emit(event: 'timeout'): boolean;
|
357
|
+
on(event: string, listener: (...args: any[]) => void): this;
|
358
|
+
on(event: 'close', listener: (hadError: boolean) => void): this;
|
359
|
+
on(event: 'connect', listener: () => void): this;
|
360
|
+
on(event: 'data', listener: (data: Buffer) => void): this;
|
361
|
+
on(event: 'drain', listener: () => void): this;
|
362
|
+
on(event: 'end', listener: () => void): this;
|
363
|
+
on(event: 'error', listener: (err: Error) => void): this;
|
364
|
+
on(event: 'lookup', listener: (err: Error, address: string, family: string | number, host: string) => void): this;
|
365
|
+
on(event: 'ready', listener: () => void): this;
|
366
|
+
on(event: 'timeout', listener: () => void): this;
|
367
|
+
once(event: string, listener: (...args: any[]) => void): this;
|
368
|
+
once(event: 'close', listener: (hadError: boolean) => void): this;
|
369
|
+
once(event: 'connect', listener: () => void): this;
|
370
|
+
once(event: 'data', listener: (data: Buffer) => void): this;
|
371
|
+
once(event: 'drain', listener: () => void): this;
|
372
|
+
once(event: 'end', listener: () => void): this;
|
373
|
+
once(event: 'error', listener: (err: Error) => void): this;
|
374
|
+
once(event: 'lookup', listener: (err: Error, address: string, family: string | number, host: string) => void): this;
|
375
|
+
once(event: 'ready', listener: () => void): this;
|
376
|
+
once(event: 'timeout', listener: () => void): this;
|
377
|
+
prependListener(event: string, listener: (...args: any[]) => void): this;
|
378
|
+
prependListener(event: 'close', listener: (hadError: boolean) => void): this;
|
379
|
+
prependListener(event: 'connect', listener: () => void): this;
|
380
|
+
prependListener(event: 'data', listener: (data: Buffer) => void): this;
|
381
|
+
prependListener(event: 'drain', listener: () => void): this;
|
382
|
+
prependListener(event: 'end', listener: () => void): this;
|
383
|
+
prependListener(event: 'error', listener: (err: Error) => void): this;
|
384
|
+
prependListener(event: 'lookup', listener: (err: Error, address: string, family: string | number, host: string) => void): this;
|
385
|
+
prependListener(event: 'ready', listener: () => void): this;
|
386
|
+
prependListener(event: 'timeout', listener: () => void): this;
|
387
|
+
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
388
|
+
prependOnceListener(event: 'close', listener: (hadError: boolean) => void): this;
|
389
|
+
prependOnceListener(event: 'connect', listener: () => void): this;
|
390
|
+
prependOnceListener(event: 'data', listener: (data: Buffer) => void): this;
|
391
|
+
prependOnceListener(event: 'drain', listener: () => void): this;
|
392
|
+
prependOnceListener(event: 'end', listener: () => void): this;
|
393
|
+
prependOnceListener(event: 'error', listener: (err: Error) => void): this;
|
394
|
+
prependOnceListener(event: 'lookup', listener: (err: Error, address: string, family: string | number, host: string) => void): this;
|
395
|
+
prependOnceListener(event: 'ready', listener: () => void): this;
|
396
|
+
prependOnceListener(event: 'timeout', listener: () => void): this;
|
397
|
+
}
|
398
|
+
interface ListenOptions extends Abortable {
|
399
|
+
port?: number | undefined;
|
400
|
+
host?: string | undefined;
|
401
|
+
backlog?: number | undefined;
|
402
|
+
path?: string | undefined;
|
403
|
+
exclusive?: boolean | undefined;
|
404
|
+
readableAll?: boolean | undefined;
|
405
|
+
writableAll?: boolean | undefined;
|
406
|
+
/**
|
407
|
+
* @default false
|
408
|
+
*/
|
409
|
+
ipv6Only?: boolean | undefined;
|
410
|
+
}
|
411
|
+
interface ServerOpts {
|
412
|
+
/**
|
413
|
+
* Indicates whether half-opened TCP connections are allowed.
|
414
|
+
* @default false
|
415
|
+
*/
|
416
|
+
allowHalfOpen?: boolean | undefined;
|
417
|
+
/**
|
418
|
+
* Indicates whether the socket should be paused on incoming connections.
|
419
|
+
* @default false
|
420
|
+
*/
|
421
|
+
pauseOnConnect?: boolean | undefined;
|
422
|
+
/**
|
423
|
+
* If set to `true`, it disables the use of Nagle's algorithm immediately after a new incoming connection is received.
|
424
|
+
* @default false
|
425
|
+
* @since v16.5.0
|
426
|
+
*/
|
427
|
+
noDelay?: boolean | undefined;
|
428
|
+
/**
|
429
|
+
* If set to `true`, it enables keep-alive functionality on the socket immediately after a new incoming connection is received,
|
430
|
+
* similarly on what is done in `socket.setKeepAlive([enable][, initialDelay])`.
|
431
|
+
* @default false
|
432
|
+
* @since v16.5.0
|
433
|
+
*/
|
434
|
+
keepAlive?: boolean | undefined;
|
435
|
+
/**
|
436
|
+
* If set to a positive number, it sets the initial delay before the first keepalive probe is sent on an idle socket.
|
437
|
+
* @default 0
|
438
|
+
* @since v16.5.0
|
439
|
+
*/
|
440
|
+
keepAliveInitialDelay?: number | undefined;
|
441
|
+
}
|
442
|
+
interface DropArgument {
|
443
|
+
localAddress?: string;
|
444
|
+
localPort?: number;
|
445
|
+
localFamily?: string;
|
446
|
+
remoteAddress?: string;
|
447
|
+
remotePort?: number;
|
448
|
+
remoteFamily?: string;
|
449
|
+
}
|
450
|
+
/**
|
451
|
+
* This class is used to create a TCP or `IPC` server.
|
452
|
+
* @since v0.1.90
|
453
|
+
*/
|
454
|
+
class Server extends EventEmitter {
|
455
|
+
constructor(connectionListener?: (socket: Socket) => void);
|
456
|
+
constructor(options?: ServerOpts, connectionListener?: (socket: Socket) => void);
|
457
|
+
/**
|
458
|
+
* Start a server listening for connections. A `net.Server` can be a TCP or
|
459
|
+
* an `IPC` server depending on what it listens to.
|
460
|
+
*
|
461
|
+
* Possible signatures:
|
462
|
+
*
|
463
|
+
* * `server.listen(handle[, backlog][, callback])`
|
464
|
+
* * `server.listen(options[, callback])`
|
465
|
+
* * `server.listen(path[, backlog][, callback])` for `IPC` servers
|
466
|
+
* * `server.listen([port[, host[, backlog]]][, callback])` for TCP servers
|
467
|
+
*
|
468
|
+
* 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'`
|
469
|
+
* event.
|
470
|
+
*
|
471
|
+
* All `listen()` methods can take a `backlog` parameter to specify the maximum
|
472
|
+
* length of the queue of pending connections. The actual length will be determined
|
473
|
+
* 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).
|
474
|
+
*
|
475
|
+
* All {@link Socket} are set to `SO_REUSEADDR` (see [`socket(7)`](https://man7.org/linux/man-pages/man7/socket.7.html) for
|
476
|
+
* details).
|
477
|
+
*
|
478
|
+
* The `server.listen()` method can be called again if and only if there was an
|
479
|
+
* error during the first `server.listen()` call or `server.close()` has been
|
480
|
+
* called. Otherwise, an `ERR_SERVER_ALREADY_LISTEN` error will be thrown.
|
481
|
+
*
|
482
|
+
* One of the most common errors raised when listening is `EADDRINUSE`.
|
483
|
+
* This happens when another server is already listening on the requested`port`/`path`/`handle`. One way to handle this would be to retry
|
484
|
+
* after a certain amount of time:
|
485
|
+
*
|
486
|
+
* ```js
|
487
|
+
* server.on('error', (e) => {
|
488
|
+
* if (e.code === 'EADDRINUSE') {
|
489
|
+
* console.log('Address in use, retrying...');
|
490
|
+
* setTimeout(() => {
|
491
|
+
* server.close();
|
492
|
+
* server.listen(PORT, HOST);
|
493
|
+
* }, 1000);
|
494
|
+
* }
|
495
|
+
* });
|
496
|
+
* ```
|
497
|
+
*/
|
498
|
+
listen(port?: number, hostname?: string, backlog?: number, listeningListener?: () => void): this;
|
499
|
+
listen(port?: number, hostname?: string, listeningListener?: () => void): this;
|
500
|
+
listen(port?: number, backlog?: number, listeningListener?: () => void): this;
|
501
|
+
listen(port?: number, listeningListener?: () => void): this;
|
502
|
+
listen(path: string, backlog?: number, listeningListener?: () => void): this;
|
503
|
+
listen(path: string, listeningListener?: () => void): this;
|
504
|
+
listen(options: ListenOptions, listeningListener?: () => void): this;
|
505
|
+
listen(handle: any, backlog?: number, listeningListener?: () => void): this;
|
506
|
+
listen(handle: any, listeningListener?: () => void): this;
|
507
|
+
/**
|
508
|
+
* Stops the server from accepting new connections and keeps existing
|
509
|
+
* connections. This function is asynchronous, the server is finally closed
|
510
|
+
* when all connections are ended and the server emits a `'close'` event.
|
511
|
+
* The optional `callback` will be called once the `'close'` event occurs. Unlike
|
512
|
+
* that event, it will be called with an `Error` as its only argument if the server
|
513
|
+
* was not open when it was closed.
|
514
|
+
* @since v0.1.90
|
515
|
+
* @param callback Called when the server is closed.
|
516
|
+
*/
|
517
|
+
close(callback?: (err?: Error) => void): this;
|
518
|
+
/**
|
519
|
+
* Returns the bound `address`, the address `family` name, and `port` of the server
|
520
|
+
* as reported by the operating system if listening on an IP socket
|
521
|
+
* (useful to find which port was assigned when getting an OS-assigned address):`{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`.
|
522
|
+
*
|
523
|
+
* For a server listening on a pipe or Unix domain socket, the name is returned
|
524
|
+
* as a string.
|
525
|
+
*
|
526
|
+
* ```js
|
527
|
+
* const server = net.createServer((socket) => {
|
528
|
+
* socket.end('goodbye\n');
|
529
|
+
* }).on('error', (err) => {
|
530
|
+
* // Handle errors here.
|
531
|
+
* throw err;
|
532
|
+
* });
|
533
|
+
*
|
534
|
+
* // Grab an arbitrary unused port.
|
535
|
+
* server.listen(() => {
|
536
|
+
* console.log('opened server on', server.address());
|
537
|
+
* });
|
538
|
+
* ```
|
539
|
+
*
|
540
|
+
* `server.address()` returns `null` before the `'listening'` event has been
|
541
|
+
* emitted or after calling `server.close()`.
|
542
|
+
* @since v0.1.90
|
543
|
+
*/
|
544
|
+
address(): AddressInfo | string | null;
|
545
|
+
/**
|
546
|
+
* Asynchronously get the number of concurrent connections on the server. Works
|
547
|
+
* when sockets were sent to forks.
|
548
|
+
*
|
549
|
+
* Callback should take two arguments `err` and `count`.
|
550
|
+
* @since v0.9.7
|
551
|
+
*/
|
552
|
+
getConnections(cb: (error: Error | null, count: number) => void): void;
|
553
|
+
/**
|
554
|
+
* 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).
|
555
|
+
* If the server is `ref`ed calling `ref()` again will have no effect.
|
556
|
+
* @since v0.9.1
|
557
|
+
*/
|
558
|
+
ref(): this;
|
559
|
+
/**
|
560
|
+
* Calling `unref()` on a server will allow the program to exit if this is the only
|
561
|
+
* active server in the event system. If the server is already `unref`ed calling`unref()` again will have no effect.
|
562
|
+
* @since v0.9.1
|
563
|
+
*/
|
564
|
+
unref(): this;
|
565
|
+
/**
|
566
|
+
* Set this property to reject connections when the server's connection count gets
|
567
|
+
* high.
|
568
|
+
*
|
569
|
+
* It is not recommended to use this option once a socket has been sent to a child
|
570
|
+
* with `child_process.fork()`.
|
571
|
+
* @since v0.2.0
|
572
|
+
*/
|
573
|
+
maxConnections: number;
|
574
|
+
connections: number;
|
575
|
+
/**
|
576
|
+
* Indicates whether or not the server is listening for connections.
|
577
|
+
* @since v5.7.0
|
578
|
+
*/
|
579
|
+
listening: boolean;
|
580
|
+
/**
|
581
|
+
* events.EventEmitter
|
582
|
+
* 1. close
|
583
|
+
* 2. connection
|
584
|
+
* 3. error
|
585
|
+
* 4. listening
|
586
|
+
* 5. drop
|
587
|
+
*/
|
588
|
+
addListener(event: string, listener: (...args: any[]) => void): this;
|
589
|
+
addListener(event: 'close', listener: () => void): this;
|
590
|
+
addListener(event: 'connection', listener: (socket: Socket) => void): this;
|
591
|
+
addListener(event: 'error', listener: (err: Error) => void): this;
|
592
|
+
addListener(event: 'listening', listener: () => void): this;
|
593
|
+
addListener(event: 'drop', listener: (data?: DropArgument) => void): this;
|
594
|
+
emit(event: string | symbol, ...args: any[]): boolean;
|
595
|
+
emit(event: 'close'): boolean;
|
596
|
+
emit(event: 'connection', socket: Socket): boolean;
|
597
|
+
emit(event: 'error', err: Error): boolean;
|
598
|
+
emit(event: 'listening'): boolean;
|
599
|
+
emit(event: 'drop', data?: DropArgument): boolean;
|
600
|
+
on(event: string, listener: (...args: any[]) => void): this;
|
601
|
+
on(event: 'close', listener: () => void): this;
|
602
|
+
on(event: 'connection', listener: (socket: Socket) => void): this;
|
603
|
+
on(event: 'error', listener: (err: Error) => void): this;
|
604
|
+
on(event: 'listening', listener: () => void): this;
|
605
|
+
on(event: 'drop', listener: (data?: DropArgument) => void): this;
|
606
|
+
once(event: string, listener: (...args: any[]) => void): this;
|
607
|
+
once(event: 'close', listener: () => void): this;
|
608
|
+
once(event: 'connection', listener: (socket: Socket) => void): this;
|
609
|
+
once(event: 'error', listener: (err: Error) => void): this;
|
610
|
+
once(event: 'listening', listener: () => void): this;
|
611
|
+
once(event: 'drop', listener: (data?: DropArgument) => void): this;
|
612
|
+
prependListener(event: string, listener: (...args: any[]) => void): this;
|
613
|
+
prependListener(event: 'close', listener: () => void): this;
|
614
|
+
prependListener(event: 'connection', listener: (socket: Socket) => void): this;
|
615
|
+
prependListener(event: 'error', listener: (err: Error) => void): this;
|
616
|
+
prependListener(event: 'listening', listener: () => void): this;
|
617
|
+
prependListener(event: 'drop', listener: (data?: DropArgument) => void): this;
|
618
|
+
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
619
|
+
prependOnceListener(event: 'close', listener: () => void): this;
|
620
|
+
prependOnceListener(event: 'connection', listener: (socket: Socket) => void): this;
|
621
|
+
prependOnceListener(event: 'error', listener: (err: Error) => void): this;
|
622
|
+
prependOnceListener(event: 'listening', listener: () => void): this;
|
623
|
+
prependOnceListener(event: 'drop', listener: (data?: DropArgument) => void): this;
|
624
|
+
}
|
625
|
+
type IPVersion = 'ipv4' | 'ipv6';
|
626
|
+
/**
|
627
|
+
* The `BlockList` object can be used with some network APIs to specify rules for
|
628
|
+
* disabling inbound or outbound access to specific IP addresses, IP ranges, or
|
629
|
+
* IP subnets.
|
630
|
+
* @since v15.0.0, v14.18.0
|
631
|
+
*/
|
632
|
+
class BlockList {
|
633
|
+
/**
|
634
|
+
* Adds a rule to block the given IP address.
|
635
|
+
* @since v15.0.0, v14.18.0
|
636
|
+
* @param address An IPv4 or IPv6 address.
|
637
|
+
* @param [type='ipv4'] Either `'ipv4'` or `'ipv6'`.
|
638
|
+
*/
|
639
|
+
addAddress(address: string, type?: IPVersion): void;
|
640
|
+
addAddress(address: SocketAddress): void;
|
641
|
+
/**
|
642
|
+
* Adds a rule to block a range of IP addresses from `start` (inclusive) to`end` (inclusive).
|
643
|
+
* @since v15.0.0, v14.18.0
|
644
|
+
* @param start The starting IPv4 or IPv6 address in the range.
|
645
|
+
* @param end The ending IPv4 or IPv6 address in the range.
|
646
|
+
* @param [type='ipv4'] Either `'ipv4'` or `'ipv6'`.
|
647
|
+
*/
|
648
|
+
addRange(start: string, end: string, type?: IPVersion): void;
|
649
|
+
addRange(start: SocketAddress, end: SocketAddress): void;
|
650
|
+
/**
|
651
|
+
* Adds a rule to block a range of IP addresses specified as a subnet mask.
|
652
|
+
* @since v15.0.0, v14.18.0
|
653
|
+
* @param net The network IPv4 or IPv6 address.
|
654
|
+
* @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`.
|
655
|
+
* @param [type='ipv4'] Either `'ipv4'` or `'ipv6'`.
|
656
|
+
*/
|
657
|
+
addSubnet(net: SocketAddress, prefix: number): void;
|
658
|
+
addSubnet(net: string, prefix: number, type?: IPVersion): void;
|
659
|
+
/**
|
660
|
+
* Returns `true` if the given IP address matches any of the rules added to the`BlockList`.
|
661
|
+
*
|
662
|
+
* ```js
|
663
|
+
* const blockList = new net.BlockList();
|
664
|
+
* blockList.addAddress('123.123.123.123');
|
665
|
+
* blockList.addRange('10.0.0.1', '10.0.0.10');
|
666
|
+
* blockList.addSubnet('8592:757c:efae:4e45::', 64, 'ipv6');
|
667
|
+
*
|
668
|
+
* console.log(blockList.check('123.123.123.123')); // Prints: true
|
669
|
+
* console.log(blockList.check('10.0.0.3')); // Prints: true
|
670
|
+
* console.log(blockList.check('222.111.111.222')); // Prints: false
|
671
|
+
*
|
672
|
+
* // IPv6 notation for IPv4 addresses works:
|
673
|
+
* console.log(blockList.check('::ffff:7b7b:7b7b', 'ipv6')); // Prints: true
|
674
|
+
* console.log(blockList.check('::ffff:123.123.123.123', 'ipv6')); // Prints: true
|
675
|
+
* ```
|
676
|
+
* @since v15.0.0, v14.18.0
|
677
|
+
* @param address The IP address to check
|
678
|
+
* @param [type='ipv4'] Either `'ipv4'` or `'ipv6'`.
|
679
|
+
*/
|
680
|
+
check(address: SocketAddress): boolean;
|
681
|
+
check(address: string, type?: IPVersion): boolean;
|
682
|
+
}
|
683
|
+
interface TcpNetConnectOpts extends TcpSocketConnectOpts, SocketConstructorOpts {
|
684
|
+
timeout?: number | undefined;
|
685
|
+
}
|
686
|
+
interface IpcNetConnectOpts extends IpcSocketConnectOpts, SocketConstructorOpts {
|
687
|
+
timeout?: number | undefined;
|
688
|
+
}
|
689
|
+
type NetConnectOpts = TcpNetConnectOpts | IpcNetConnectOpts;
|
690
|
+
/**
|
691
|
+
* Creates a new TCP or `IPC` server.
|
692
|
+
*
|
693
|
+
* If `allowHalfOpen` is set to `true`, when the other end of the socket
|
694
|
+
* signals the end of transmission, the server will only send back the end of
|
695
|
+
* transmission when `socket.end()` is explicitly called. For example, in the
|
696
|
+
* context of TCP, when a FIN packed is received, a FIN packed is sent
|
697
|
+
* back only when `socket.end()` is explicitly called. Until then the
|
698
|
+
* 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.
|
699
|
+
*
|
700
|
+
* If `pauseOnConnect` is set to `true`, then the socket associated with each
|
701
|
+
* incoming connection will be paused, and no data will be read from its handle.
|
702
|
+
* This allows connections to be passed between processes without any data being
|
703
|
+
* read by the original process. To begin reading data from a paused socket, call `socket.resume()`.
|
704
|
+
*
|
705
|
+
* The server can be a TCP server or an `IPC` server, depending on what it `listen()` to.
|
706
|
+
*
|
707
|
+
* Here is an example of a TCP echo server which listens for connections
|
708
|
+
* on port 8124:
|
709
|
+
*
|
710
|
+
* ```js
|
711
|
+
* const net = require('net');
|
712
|
+
* const server = net.createServer((c) => {
|
713
|
+
* // 'connection' listener.
|
714
|
+
* console.log('client connected');
|
715
|
+
* c.on('end', () => {
|
716
|
+
* console.log('client disconnected');
|
717
|
+
* });
|
718
|
+
* c.write('hello\r\n');
|
719
|
+
* c.pipe(c);
|
720
|
+
* });
|
721
|
+
* server.on('error', (err) => {
|
722
|
+
* throw err;
|
723
|
+
* });
|
724
|
+
* server.listen(8124, () => {
|
725
|
+
* console.log('server bound');
|
726
|
+
* });
|
727
|
+
* ```
|
728
|
+
*
|
729
|
+
* Test this by using `telnet`:
|
730
|
+
*
|
731
|
+
* ```console
|
732
|
+
* $ telnet localhost 8124
|
733
|
+
* ```
|
734
|
+
*
|
735
|
+
* To listen on the socket `/tmp/echo.sock`:
|
736
|
+
*
|
737
|
+
* ```js
|
738
|
+
* server.listen('/tmp/echo.sock', () => {
|
739
|
+
* console.log('server bound');
|
740
|
+
* });
|
741
|
+
* ```
|
742
|
+
*
|
743
|
+
* Use `nc` to connect to a Unix domain socket server:
|
744
|
+
*
|
745
|
+
* ```console
|
746
|
+
* $ nc -U /tmp/echo.sock
|
747
|
+
* ```
|
748
|
+
* @since v0.5.0
|
749
|
+
* @param connectionListener Automatically set as a listener for the {@link 'connection'} event.
|
750
|
+
*/
|
751
|
+
function createServer(connectionListener?: (socket: Socket) => void): Server;
|
752
|
+
function createServer(options?: ServerOpts, connectionListener?: (socket: Socket) => void): Server;
|
753
|
+
/**
|
754
|
+
* Aliases to {@link createConnection}.
|
755
|
+
*
|
756
|
+
* Possible signatures:
|
757
|
+
*
|
758
|
+
* * {@link connect}
|
759
|
+
* * {@link connect} for `IPC` connections.
|
760
|
+
* * {@link connect} for TCP connections.
|
761
|
+
*/
|
762
|
+
function connect(options: NetConnectOpts, connectionListener?: () => void): Socket;
|
763
|
+
function connect(port: number, host?: string, connectionListener?: () => void): Socket;
|
764
|
+
function connect(path: string, connectionListener?: () => void): Socket;
|
765
|
+
/**
|
766
|
+
* A factory function, which creates a new {@link Socket},
|
767
|
+
* immediately initiates connection with `socket.connect()`,
|
768
|
+
* then returns the `net.Socket` that starts the connection.
|
769
|
+
*
|
770
|
+
* When the connection is established, a `'connect'` event will be emitted
|
771
|
+
* on the returned socket. The last parameter `connectListener`, if supplied,
|
772
|
+
* will be added as a listener for the `'connect'` event **once**.
|
773
|
+
*
|
774
|
+
* Possible signatures:
|
775
|
+
*
|
776
|
+
* * {@link createConnection}
|
777
|
+
* * {@link createConnection} for `IPC` connections.
|
778
|
+
* * {@link createConnection} for TCP connections.
|
779
|
+
*
|
780
|
+
* The {@link connect} function is an alias to this function.
|
781
|
+
*/
|
782
|
+
function createConnection(options: NetConnectOpts, connectionListener?: () => void): Socket;
|
783
|
+
function createConnection(port: number, host?: string, connectionListener?: () => void): Socket;
|
784
|
+
function createConnection(path: string, connectionListener?: () => void): Socket;
|
785
|
+
/**
|
786
|
+
* Returns `6` if `input` is an IPv6 address. Returns `4` if `input` is an IPv4
|
787
|
+
* address in [dot-decimal notation](https://en.wikipedia.org/wiki/Dot-decimal_notation) with no leading zeroes. Otherwise, returns`0`.
|
788
|
+
*
|
789
|
+
* ```js
|
790
|
+
* net.isIP('::1'); // returns 6
|
791
|
+
* net.isIP('127.0.0.1'); // returns 4
|
792
|
+
* net.isIP('127.000.000.001'); // returns 0
|
793
|
+
* net.isIP('127.0.0.1/24'); // returns 0
|
794
|
+
* net.isIP('fhqwhgads'); // returns 0
|
795
|
+
* ```
|
796
|
+
* @since v0.3.0
|
797
|
+
*/
|
798
|
+
function isIP(input: string): number;
|
799
|
+
/**
|
800
|
+
* Returns `true` if `input` is an IPv4 address in [dot-decimal notation](https://en.wikipedia.org/wiki/Dot-decimal_notation) with no
|
801
|
+
* leading zeroes. Otherwise, returns `false`.
|
802
|
+
*
|
803
|
+
* ```js
|
804
|
+
* net.isIPv4('127.0.0.1'); // returns true
|
805
|
+
* net.isIPv4('127.000.000.001'); // returns false
|
806
|
+
* net.isIPv4('127.0.0.1/24'); // returns false
|
807
|
+
* net.isIPv4('fhqwhgads'); // returns false
|
808
|
+
* ```
|
809
|
+
* @since v0.3.0
|
810
|
+
*/
|
811
|
+
function isIPv4(input: string): boolean;
|
812
|
+
/**
|
813
|
+
* Returns `true` if `input` is an IPv6 address. Otherwise, returns `false`.
|
814
|
+
*
|
815
|
+
* ```js
|
816
|
+
* net.isIPv6('::1'); // returns true
|
817
|
+
* net.isIPv6('fhqwhgads'); // returns false
|
818
|
+
* ```
|
819
|
+
* @since v0.3.0
|
820
|
+
*/
|
821
|
+
function isIPv6(input: string): boolean;
|
822
|
+
interface SocketAddressInitOptions {
|
823
|
+
/**
|
824
|
+
* The network address as either an IPv4 or IPv6 string.
|
825
|
+
* @default 127.0.0.1
|
826
|
+
*/
|
827
|
+
address?: string | undefined;
|
828
|
+
/**
|
829
|
+
* @default `'ipv4'`
|
830
|
+
*/
|
831
|
+
family?: IPVersion | undefined;
|
832
|
+
/**
|
833
|
+
* An IPv6 flow-label used only if `family` is `'ipv6'`.
|
834
|
+
* @default 0
|
835
|
+
*/
|
836
|
+
flowlabel?: number | undefined;
|
837
|
+
/**
|
838
|
+
* An IP port.
|
839
|
+
* @default 0
|
840
|
+
*/
|
841
|
+
port?: number | undefined;
|
842
|
+
}
|
843
|
+
/**
|
844
|
+
* @since v15.14.0, v14.18.0
|
845
|
+
*/
|
846
|
+
class SocketAddress {
|
847
|
+
constructor(options: SocketAddressInitOptions);
|
848
|
+
/**
|
849
|
+
* @since v15.14.0, v14.18.0
|
850
|
+
*/
|
851
|
+
readonly address: string;
|
852
|
+
/**
|
853
|
+
* Either \`'ipv4'\` or \`'ipv6'\`.
|
854
|
+
* @since v15.14.0, v14.18.0
|
855
|
+
*/
|
856
|
+
readonly family: IPVersion;
|
857
|
+
/**
|
858
|
+
* @since v15.14.0, v14.18.0
|
859
|
+
*/
|
860
|
+
readonly port: number;
|
861
|
+
/**
|
862
|
+
* @since v15.14.0, v14.18.0
|
863
|
+
*/
|
864
|
+
readonly flowlabel: number;
|
865
|
+
}
|
866
|
+
}
|
867
|
+
declare module 'node:net' {
|
868
|
+
export * from 'net';
|
869
|
+
}
|