summaryrefslogtreecommitdiff
path: root/doc/api/net.md
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2021-10-10 21:55:04 -0700
committerAntoine du Hamel <duhamelantoine1995@gmail.com>2021-10-20 11:59:11 +0200
commitd0b58c0287e67a139137aa906819d95f8314b093 (patch)
treee9a92870138d89b608b1c6e6568611744c32c4f2 /doc/api/net.md
parenta7c17e08de658cbc0beefd8e9583803b5a62ac7e (diff)
downloadnode-new-d0b58c0287e67a139137aa906819d95f8314b093.tar.gz
doc: format doc/api/*.md with markdown formatter
PR-URL: https://github.com/nodejs/node/pull/40403 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Zijian Liu <lxxyxzj@gmail.com> Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Diffstat (limited to 'doc/api/net.md')
-rw-r--r--doc/api/net.md101
1 files changed, 86 insertions, 15 deletions
diff --git a/doc/api/net.md b/doc/api/net.md
index 6d5487b674..8d3aaf1b6c 100644
--- a/doc/api/net.md
+++ b/doc/api/net.md
@@ -40,11 +40,11 @@ applies when a Node.js API creates a Unix domain socket but the program then
crashes. In short, a Unix domain socket will be visible in the filesystem and
will persist until unlinked.
-On Windows, the local domain is implemented using a named pipe. The path *must*
+On Windows, the local domain is implemented using a named pipe. The path _must_
refer to an entry in `\\?\pipe\` or `\\.\pipe\`. Any characters are permitted,
but the latter may do some processing of pipe names, such as resolving `..`
sequences. Despite how it might look, the pipe namespace is flat. Pipes will
-*not persist*. They are removed when the last reference to them is closed.
+_not persist_. They are removed when the last reference to them is closed.
Unlike Unix domain sockets, Windows will close and remove the pipe when the
owning process exits.
@@ -57,6 +57,7 @@ net.createServer().listen(
```
## Class: `net.BlockList`
+
<!-- YAML
added:
- v15.0.0
@@ -68,6 +69,7 @@ disabling inbound or outbound access to specific IP addresses, IP ranges, or
IP subnets.
### `blockList.addAddress(address[, type])`
+
<!-- YAML
added:
- v15.0.0
@@ -80,6 +82,7 @@ added:
Adds a rule to block the given IP address.
### `blockList.addRange(start, end[, type])`
+
<!-- YAML
added:
- v15.0.0
@@ -95,6 +98,7 @@ Adds a rule to block a range of IP addresses from `start` (inclusive) to
`end` (inclusive).
### `blockList.addSubnet(net, prefix[, type])`
+
<!-- YAML
added:
- v15.0.0
@@ -110,6 +114,7 @@ added:
Adds a rule to block a range of IP addresses specified as a subnet mask.
### `blockList.check(address[, type])`
+
<!-- YAML
added:
- v15.0.0
@@ -139,23 +144,27 @@ console.log(blockList.check('::ffff:123.123.123.123', 'ipv6')); // Prints: true
```
### `blockList.rules`
+
<!-- YAML
added:
- v15.0.0
- v14.18.0
-->
-* Type: {string[]}
+* Type: {string\[]}
The list of rules added to the blocklist.
## Class: `net.SocketAddress`
+
<!-- YAML
added:
- v15.14.0
- v14.18.0
-->
+
### `new net.SocketAddress([options])`
+
<!-- YAML
added:
- v15.14.0
@@ -166,11 +175,13 @@ added:
* `address` {string} The network address as either an IPv4 or IPv6 string.
**Default**: `'127.0.0.1'` if `family` is `'ipv4'`; `'::'` if `family` is
`'ipv6'`.
- * `family` {string} One of either `'ipv4'` or 'ipv6'`. **Default**: `'ipv4'`.
+ * `family` {string} One of either `'ipv4'` or `'ipv6'`.
+ **Default**: `'ipv4'`.
* `flowlabel` {number} An IPv6 flow-label used only if `family` is `'ipv6'`.
* `port` {number} An IP port.
### `socketaddress.address`
+
<!-- YAML
added:
- v15.14.0
@@ -180,6 +191,7 @@ added:
* Type {string}
### `socketaddress.family`
+
<!-- YAML
added:
- v15.14.0
@@ -189,6 +201,7 @@ added:
* Type {string} Either `'ipv4'` or `'ipv6'`.
### `socketaddress.flowlabel`
+
<!-- YAML
added:
- v15.14.0
@@ -198,6 +211,7 @@ added:
* Type {number}
### `socketaddress.port`
+
<!-- YAML
added:
- v15.14.0
@@ -207,6 +221,7 @@ added:
* Type {number}
## Class: `net.Server`
+
<!-- YAML
added: v0.1.90
-->
@@ -226,6 +241,7 @@ This class is used to create a TCP or [IPC][] server.
`net.Server` is an [`EventEmitter`][] with the following events:
### Event: `'close'`
+
<!-- YAML
added: v0.5.0
-->
@@ -234,6 +250,7 @@ Emitted when the server closes. If connections exist, this
event is not emitted until all connections are ended.
### Event: `'connection'`
+
<!-- YAML
added: v0.1.90
-->
@@ -244,6 +261,7 @@ Emitted when a new connection is made. `socket` is an instance of
`net.Socket`.
### Event: `'error'`
+
<!-- YAML
added: v0.1.90
-->
@@ -256,6 +274,7 @@ event will **not** be emitted directly following this event unless
[`server.listen()`][].
### Event: `'listening'`
+
<!-- YAML
added: v0.1.90
-->
@@ -263,6 +282,7 @@ added: v0.1.90
Emitted when the server has been bound after calling [`server.listen()`][].
### `server.address()`
+
<!-- YAML
added: v0.1.90
-->
@@ -295,6 +315,7 @@ server.listen(() => {
emitted or after calling `server.close()`.
### `server.close([callback])`
+
<!-- YAML
added: v0.1.90
-->
@@ -310,6 +331,7 @@ that event, it will be called with an `Error` as its only argument if the server
was not open when it was closed.
### `server.getConnections(callback)`
+
<!-- YAML
added: v0.9.7
-->
@@ -329,15 +351,12 @@ an [IPC][] server depending on what it listens to.
Possible signatures:
-<!--lint disable no-undefined-references-->
* [`server.listen(handle[, backlog][, callback])`][`server.listen(handle)`]
* [`server.listen(options[, callback])`][`server.listen(options)`]
* [`server.listen(path[, backlog][, callback])`][`server.listen(path)`]
for [IPC][] servers
-* <a href="#serverlistenport-host-backlog-callback">
- <code>server.listen([port[, host[, backlog]]][, callback])</code></a>
+* [`server.listen([port[, host[, backlog]]][, callback])`][`server.listen(port)`]
for TCP servers
-<!--lint enable no-undefined-references-->
This function is asynchronous. When the server starts listening, the
[`'listening'`][] event will be emitted. The last parameter `callback`
@@ -373,6 +392,7 @@ server.on('error', (e) => {
```
#### `server.listen(handle[, backlog][, callback])`
+
<!-- YAML
added: v0.5.10
-->
@@ -392,6 +412,7 @@ valid file descriptor.
Listening on a file descriptor is not supported on Windows.
#### `server.listen(options[, callback])`
+
<!-- YAML
added: v0.11.14
changes:
@@ -423,14 +444,11 @@ changes:
functions.
* Returns: {net.Server}
-<!--lint disable no-undefined-references-->
If `port` is specified, it behaves the same as
-<a href="#serverlistenport-host-backlog-callback">
-<code>server.listen([port[, host[, backlog]]][, callback])</code></a>.
+[`server.listen([port[, host[, backlog]]][, callback])`][`server.listen(port)`].
Otherwise, if `path` is specified, it behaves the same as
[`server.listen(path[, backlog][, callback])`][`server.listen(path)`].
If none of them is specified, an error will be thrown.
-<!--lint enable no-undefined-references-->
If `exclusive` is `false` (default), then cluster workers will use the same
underlying handle, allowing connection handling duties to be shared. When
@@ -465,6 +483,7 @@ controller.abort();
```
#### `server.listen(path[, backlog][, callback])`
+
<!-- YAML
added: v0.1.90
-->
@@ -478,6 +497,7 @@ added: v0.1.90
Start an [IPC][] server listening for connections on the given `path`.
#### `server.listen([port[, host[, backlog]]][, callback])`
+
<!-- YAML
added: v0.1.90
-->
@@ -503,6 +523,7 @@ may cause the `net.Server` to also listen on the [unspecified IPv4 address][]
(`0.0.0.0`).
### `server.listening`
+
<!-- YAML
added: v5.7.0
-->
@@ -510,6 +531,7 @@ added: v5.7.0
* {boolean} Indicates whether or not the server is listening for connections.
### `server.maxConnections`
+
<!-- YAML
added: v0.2.0
-->
@@ -523,6 +545,7 @@ It is not recommended to use this option once a socket has been sent to a child
with [`child_process.fork()`][].
### `server.ref()`
+
<!-- YAML
added: v0.9.1
-->
@@ -530,10 +553,11 @@ added: v0.9.1
* Returns: {net.Server}
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).
+_not_ let the program exit if it's the only server left (the default behavior).
If the server is `ref`ed calling `ref()` again will have no effect.
### `server.unref()`
+
<!-- YAML
added: v0.9.1
-->
@@ -545,6 +569,7 @@ active server in the event system. If the server is already `unref`ed calling
`unref()` again will have no effect.
## Class: `net.Socket`
+
<!-- YAML
added: v0.3.4
-->
@@ -565,6 +590,7 @@ is received. For example, it is passed to the listeners of a
it to interact with the client.
### `new net.Socket([options])`
+
<!-- YAML
added: v0.3.4
changes:
@@ -594,6 +620,7 @@ The newly created socket can be either a TCP socket or a streaming [IPC][]
endpoint, depending on what it [`connect()`][`socket.connect()`] to.
### Event: `'close'`
+
<!-- YAML
added: v0.1.90
-->
@@ -604,6 +631,7 @@ Emitted once the socket is fully closed. The argument `hadError` is a boolean
which says if the socket was closed due to a transmission error.
### Event: `'connect'`
+
<!-- YAML
added: v0.1.90
-->
@@ -612,6 +640,7 @@ Emitted when a socket connection is successfully established.
See [`net.createConnection()`][].
### Event: `'data'`
+
<!-- YAML
added: v0.1.90
-->
@@ -625,6 +654,7 @@ The data will be lost if there is no listener when a `Socket`
emits a `'data'` event.
### Event: `'drain'`
+
<!-- YAML
added: v0.1.90
-->
@@ -634,6 +664,7 @@ Emitted when the write buffer becomes empty. Can be used to throttle uploads.
See also: the return values of `socket.write()`.
### Event: `'end'`
+
<!-- YAML
added: v0.1.90
-->
@@ -650,6 +681,7 @@ allowing the user to write arbitrary amounts of data. The user must call
FIN packet back).
### Event: `'error'`
+
<!-- YAML
added: v0.1.90
-->
@@ -660,6 +692,7 @@ Emitted when an error occurs. The `'close'` event will be called directly
following this event.
### Event: `'lookup'`
+
<!-- YAML
added: v0.11.3
changes:
@@ -677,6 +710,7 @@ Not applicable to Unix sockets.
* `host` {string} The host name.
### Event: `'ready'`
+
<!-- YAML
added: v9.11.0
-->
@@ -686,6 +720,7 @@ Emitted when a socket is ready to be used.
Triggered immediately after `'connect'`.
### Event: `'timeout'`
+
<!-- YAML
added: v0.1.90
-->
@@ -696,6 +731,7 @@ the socket has been idle. The user must manually close the connection.
See also: [`socket.setTimeout()`][].
### `socket.address()`
+
<!-- YAML
added: v0.1.90
-->
@@ -707,6 +743,7 @@ socket as reported by the operating system:
`{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`
### `socket.bufferSize`
+
<!-- YAML
added: v0.3.8
deprecated:
@@ -733,6 +770,7 @@ Users who experience large or growing `bufferSize` should attempt to
[`socket.pause()`][] and [`socket.resume()`][].
### `socket.bytesRead`
+
<!-- YAML
added: v0.5.3
-->
@@ -742,6 +780,7 @@ added: v0.5.3
The amount of received bytes.
### `socket.bytesWritten`
+
<!-- YAML
added: v0.5.3
-->
@@ -775,6 +814,7 @@ This function should only be used for reconnecting a socket after
behavior.
#### `socket.connect(options[, connectListener])`
+
<!-- YAML
added: v0.1.90
changes:
@@ -865,6 +905,7 @@ Alias to
called with `{ path: path }` as `options`.
#### `socket.connect(port[, host][, connectListener])`
+
<!-- YAML
added: v0.1.90
-->
@@ -882,6 +923,7 @@ Alias to
called with `{port: port, host: host}` as `options`.
### `socket.connecting`
+
<!-- YAML
added: v6.1.0
-->
@@ -897,6 +939,7 @@ that the
callback is a listener for the `'connect'` event.
### `socket.destroy([error])`
+
<!-- YAML
added: v0.1.90
-->
@@ -917,6 +960,7 @@ See [`writable.destroy()`][] for further details.
See [`writable.destroyed`][] for further details.
### `socket.end([data[, encoding]][, callback])`
+
<!-- YAML
added: v0.1.90
-->
@@ -932,6 +976,7 @@ server will still send some data.
See [`writable.end()`][] for further details.
### `socket.localAddress`
+
<!-- YAML
added: v0.9.6
-->
@@ -944,6 +989,7 @@ connects on `'192.168.1.1'`, the value of `socket.localAddress` would be
`'192.168.1.1'`.
### `socket.localPort`
+
<!-- YAML
added: v0.9.6
-->
@@ -960,6 +1006,7 @@ Pauses the reading of data. That is, [`'data'`][] events will not be emitted.
Useful to throttle back an upload.
### `socket.pending`
+
<!-- YAML
added:
- v11.2.0
@@ -973,6 +1020,7 @@ has not yet been called or because it is still in the process of connecting
(see [`socket.connecting`][]).
### `socket.ref()`
+
<!-- YAML
added: v0.9.1
-->
@@ -980,10 +1028,11 @@ added: v0.9.1
* Returns: {net.Socket} The socket itself.
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).
+_not_ let the program exit if it's the only socket left (the default behavior).
If the socket is `ref`ed calling `ref` again will have no effect.
### `socket.remoteAddress`
+
<!-- YAML
added: v0.5.10
-->
@@ -995,6 +1044,7 @@ The string representation of the remote IP address. For example,
the socket is destroyed (for example, if the client disconnected).
### `socket.remoteFamily`
+
<!-- YAML
added: v0.11.14
-->
@@ -1004,6 +1054,7 @@ added: v0.11.14
The string representation of the remote IP family. `'IPv4'` or `'IPv6'`.
### `socket.remotePort`
+
<!-- YAML
added: v0.5.10
-->
@@ -1019,6 +1070,7 @@ The numeric representation of the remote port. For example, `80` or `21`.
Resumes reading after a call to [`socket.pause()`][].
### `socket.setEncoding([encoding])`
+
<!-- YAML
added: v0.1.90
-->
@@ -1030,6 +1082,7 @@ Set the encoding for the socket as a [Readable Stream][]. See
[`readable.setEncoding()`][] for more information.
### `socket.setKeepAlive([enable][, initialDelay])`
+
<!-- YAML
added: v0.1.92
changes:
@@ -1053,12 +1106,14 @@ data packet received and the first keepalive probe. Setting `0` for
(or previous) setting.
Enabling the keep-alive functionality will set the following socket options:
+
* `SO_KEEPALIVE=1`
* `TCP_KEEPIDLE=initialDelay`
* `TCP_KEEPCNT=10`
* `TCP_KEEPINTVL=1`
### `socket.setNoDelay([noDelay])`
+
<!-- YAML
added: v0.1.90
-->
@@ -1078,6 +1133,7 @@ algorithm for the socket. Passing `false` for `noDelay` will enable Nagle's
algorithm.
### `socket.setTimeout(timeout[, callback])`
+
<!-- YAML
added: v0.1.90
-->
@@ -1107,6 +1163,7 @@ The optional `callback` parameter will be added as a one-time listener for the
[`'timeout'`][] event.
### `socket.timeout`
+
<!-- YAML
added: v10.7.0
-->
@@ -1117,6 +1174,7 @@ The socket timeout in milliseconds as set by [`socket.setTimeout()`][].
It is `undefined` if a timeout has not been set.
### `socket.unref()`
+
<!-- YAML
added: v0.9.1
-->
@@ -1128,6 +1186,7 @@ active socket in the event system. If the socket is already `unref`ed calling
`unref()` again will have no effect.
### `socket.write(data[, encoding][, callback])`
+
<!-- YAML
added: v0.1.90
-->
@@ -1151,6 +1210,7 @@ See `Writable` stream [`write()`][stream_writable_write] method for more
information.
### `socket.readyState`
+
<!-- YAML
added: v0.5.0
-->
@@ -1178,6 +1238,7 @@ Possible signatures:
for TCP connections.
### `net.connect(options[, connectListener])`
+
<!-- YAML
added: v0.7.0
-->
@@ -1190,6 +1251,7 @@ Alias to
[`net.createConnection(options[, connectListener])`][`net.createConnection(options)`].
### `net.connect(path[, connectListener])`
+
<!-- YAML
added: v0.1.90
-->
@@ -1202,6 +1264,7 @@ Alias to
[`net.createConnection(path[, connectListener])`][`net.createConnection(path)`].
### `net.connect(port[, host][, connectListener])`
+
<!-- YAML
added: v0.1.90
-->
@@ -1235,6 +1298,7 @@ Possible signatures:
The [`net.connect()`][] function is an alias to this function.
### `net.createConnection(options[, connectListener])`
+
<!-- YAML
added: v0.1.90
-->
@@ -1284,6 +1348,7 @@ const client = net.createConnection({ path: '/tmp/echo.sock' });
```
### `net.createConnection(path[, connectListener])`
+
<!-- YAML
added: v0.1.90
-->
@@ -1305,6 +1370,7 @@ immediately initiates connection with
then returns the `net.Socket` that starts the connection.
### `net.createConnection(port[, host][, connectListener])`
+
<!-- YAML
added: v0.1.90
-->
@@ -1313,7 +1379,7 @@ added: v0.1.90
[`socket.connect(port[, host][, connectListener])`][`socket.connect(port)`].
* `host` {string} Host the socket should connect to. Will be passed to
[`socket.connect(port[, host][, connectListener])`][`socket.connect(port)`].
- **Default:** `'localhost'`.
+ **Default:** `'localhost'`.
* `connectListener` {Function} Common parameter of the
[`net.createConnection()`][] functions, an "once" listener for the
`'connect'` event on the initiating socket. Will be passed to
@@ -1328,6 +1394,7 @@ immediately initiates connection with
then returns the `net.Socket` that starts the connection.
## `net.createServer([options][, connectionListener])`
+
<!-- YAML
added: v0.5.0
-->
@@ -1404,6 +1471,7 @@ $ nc -U /tmp/echo.sock
```
## `net.isIP(input)`
+
<!-- YAML
added: v0.3.0
-->
@@ -1416,6 +1484,7 @@ returns `4` for IP version 4 addresses, and returns `6` for IP version 6
addresses.
## `net.isIPv4(input)`
+
<!-- YAML
added: v0.3.0
-->
@@ -1426,6 +1495,7 @@ added: v0.3.0
Returns `true` if input is a version 4 IP address, otherwise returns `false`.
## `net.isIPv6(input)`
+
<!-- YAML
added: v0.3.0
-->
@@ -1469,6 +1539,7 @@ Returns `true` if input is a version 6 IP address, otherwise returns `false`.
[`server.listen(handle)`]: #serverlistenhandle-backlog-callback
[`server.listen(options)`]: #serverlistenoptions-callback
[`server.listen(path)`]: #serverlistenpath-backlog-callback
+[`server.listen(port)`]: #serverlistenport-host-backlog-callback
[`socket(7)`]: https://man7.org/linux/man-pages/man7/socket.7.html
[`socket.connect()`]: #socketconnect
[`socket.connect(options)`]: #socketconnectoptions-connectlistener