diff options
Diffstat (limited to 'doc')
-rw-r--r-- | doc/api/net.md | 138 |
1 files changed, 69 insertions, 69 deletions
diff --git a/doc/api/net.md b/doc/api/net.md index c633f937b8e..13bcd60cf48 100644 --- a/doc/api/net.md +++ b/doc/api/net.md @@ -55,7 +55,7 @@ net.createServer().listen( path.join('\\\\?\\pipe', process.cwd(), 'myctl')); ``` -## Class: net.Server +## Class: `net.Server` <!-- YAML added: v0.1.90 --> @@ -64,7 +64,7 @@ added: v0.1.90 This class is used to create a TCP or [IPC][] server. -### new net.Server(\[options\]\[, connectionListener\]) +### `new net.Server([options][, connectionListener])` * `options` {Object} See [`net.createServer([options][, connectionListener])`][`net.createServer()`]. @@ -74,7 +74,7 @@ This class is used to create a TCP or [IPC][] server. `net.Server` is an [`EventEmitter`][] with the following events: -### Event: 'close' +### Event: `'close'` <!-- YAML added: v0.5.0 --> @@ -82,7 +82,7 @@ added: v0.5.0 Emitted when the server closes. If connections exist, this event is not emitted until all connections are ended. -### Event: 'connection' +### Event: `'connection'` <!-- YAML added: v0.1.90 --> @@ -92,7 +92,7 @@ added: v0.1.90 Emitted when a new connection is made. `socket` is an instance of `net.Socket`. -### Event: 'error' +### Event: `'error'` <!-- YAML added: v0.1.90 --> @@ -104,14 +104,14 @@ event will **not** be emitted directly following this event unless [`server.close()`][] is manually called. See the example in discussion of [`server.listen()`][]. -### Event: 'listening' +### Event: `'listening'` <!-- YAML added: v0.1.90 --> Emitted when the server has been bound after calling [`server.listen()`][]. -### server.address() +### `server.address()` <!-- YAML added: v0.1.90 --> @@ -142,7 +142,7 @@ server.listen(() => { Don't call `server.address()` until the `'listening'` event has been emitted. -### server.close(\[callback\]) +### `server.close([callback])` <!-- YAML added: v0.1.90 --> @@ -157,7 +157,7 @@ The optional `callback` will be called once the `'close'` event occurs. Unlike that event, it will be called with an `Error` as its only argument if the server was not open when it was closed. -### server.connections +### `server.connections` <!-- YAML added: v0.2.0 deprecated: v0.9.7 @@ -173,7 +173,7 @@ This becomes `null` when sending a socket to a child with [`child_process.fork()`][]. To poll forks and get current number of active connections, use asynchronous [`server.getConnections()`][] instead. -### server.getConnections(callback) +### `server.getConnections(callback)` <!-- YAML added: v0.9.7 --> @@ -186,7 +186,7 @@ when sockets were sent to forks. Callback should take two arguments `err` and `count`. -### server.listen() +### `server.listen()` Start a server listening for connections. A `net.Server` can be a TCP or an [IPC][] server depending on what it listens to. @@ -234,7 +234,7 @@ server.on('error', (e) => { }); ``` -#### server.listen(handle\[, backlog\]\[, callback\]) +#### `server.listen(handle[, backlog][, callback])` <!-- YAML added: v0.5.10 --> @@ -253,7 +253,7 @@ valid file descriptor. Listening on a file descriptor is not supported on Windows. -#### server.listen(options\[, callback\]) +#### `server.listen(options[, callback])` <!-- YAML added: v0.11.14 changes: @@ -306,7 +306,7 @@ Starting an IPC server as root may cause the server path to be inaccessible for unprivileged users. Using `readableAll` and `writableAll` will make the server accessible for all users. -#### server.listen(path\[, backlog\]\[, callback\]) +#### `server.listen(path[, backlog][, callback])` <!-- YAML added: v0.1.90 --> @@ -319,7 +319,7 @@ added: v0.1.90 Start an [IPC][] server listening for connections on the given `path`. -#### server.listen(\[port\[, host\[, backlog\]\]\]\[, callback\]) +#### `server.listen([port[, host[, backlog]]][, callback])` <!-- YAML added: v0.1.90 --> @@ -344,14 +344,14 @@ In most operating systems, listening to the [unspecified IPv6 address][] (`::`) may cause the `net.Server` to also listen on the [unspecified IPv4 address][] (`0.0.0.0`). -### server.listening +### `server.listening` <!-- YAML added: v5.7.0 --> * {boolean} Indicates whether or not the server is listening for connections. -### server.maxConnections +### `server.maxConnections` <!-- YAML added: v0.2.0 --> @@ -364,7 +364,7 @@ high. It is not recommended to use this option once a socket has been sent to a child with [`child_process.fork()`][]. -### server.ref() +### `server.ref()` <!-- YAML added: v0.9.1 --> @@ -375,7 +375,7 @@ 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). If the server is `ref`ed calling `ref()` again will have no effect. -### server.unref() +### `server.unref()` <!-- YAML added: v0.9.1 --> @@ -386,7 +386,7 @@ Calling `unref()` on a server will allow the program to exit if this is the only active server in the event system. If the server is already `unref`ed calling `unref()` again will have no effect. -## Class: net.Socket +## Class: `net.Socket` <!-- YAML added: v0.3.4 --> @@ -406,7 +406,7 @@ is received. For example, it is passed to the listeners of a [`'connection'`][] event emitted on a [`net.Server`][], so the user can use it to interact with the client. -### new net.Socket(\[options\]) +### `new net.Socket([options])` <!-- YAML added: v0.3.4 --> @@ -428,7 +428,7 @@ Creates a new socket object. 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' +### Event: `'close'` <!-- YAML added: v0.1.90 --> @@ -438,7 +438,7 @@ added: v0.1.90 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' +### Event: `'connect'` <!-- YAML added: v0.1.90 --> @@ -446,7 +446,7 @@ added: v0.1.90 Emitted when a socket connection is successfully established. See [`net.createConnection()`][]. -### Event: 'data' +### Event: `'data'` <!-- YAML added: v0.1.90 --> @@ -459,7 +459,7 @@ Emitted when data is received. The argument `data` will be a `Buffer` or The data will be lost if there is no listener when a `Socket` emits a `'data'` event. -### Event: 'drain' +### Event: `'drain'` <!-- YAML added: v0.1.90 --> @@ -468,7 +468,7 @@ Emitted when the write buffer becomes empty. Can be used to throttle uploads. See also: the return values of `socket.write()`. -### Event: 'end' +### Event: `'end'` <!-- YAML added: v0.1.90 --> @@ -484,7 +484,7 @@ user to write arbitrary amounts of data. The user must call [`end()`][`socket.end()`] explicitly to close the connection (i.e. sending a FIN packet back). -### Event: 'error' +### Event: `'error'` <!-- YAML added: v0.1.90 --> @@ -494,7 +494,7 @@ added: v0.1.90 Emitted when an error occurs. The `'close'` event will be called directly following this event. -### Event: 'lookup' +### Event: `'lookup'` <!-- YAML added: v0.11.3 changes: @@ -511,7 +511,7 @@ Not applicable to Unix sockets. * `family` {string|null} The address type. See [`dns.lookup()`][]. * `host` {string} The hostname. -### Event: 'ready' +### Event: `'ready'` <!-- YAML added: v9.11.0 --> @@ -520,7 +520,7 @@ Emitted when a socket is ready to be used. Triggered immediately after `'connect'`. -### Event: 'timeout' +### Event: `'timeout'` <!-- YAML added: v0.1.90 --> @@ -530,7 +530,7 @@ the socket has been idle. The user must manually close the connection. See also: [`socket.setTimeout()`][]. -### socket.address() +### `socket.address()` <!-- YAML added: v0.1.90 --> @@ -541,7 +541,7 @@ Returns the bound `address`, the address `family` name and `port` of the socket as reported by the operating system: `{ port: 12346, family: 'IPv4', address: '127.0.0.1' }` -### socket.bufferSize +### `socket.bufferSize` <!-- YAML added: v0.3.8 --> @@ -563,7 +563,7 @@ Users who experience large or growing `bufferSize` should attempt to "throttle" the data flows in their program with [`socket.pause()`][] and [`socket.resume()`][]. -### socket.bytesRead +### `socket.bytesRead` <!-- YAML added: v0.5.3 --> @@ -572,7 +572,7 @@ added: v0.5.3 The amount of received bytes. -### socket.bytesWritten +### `socket.bytesWritten` <!-- YAML added: v0.5.3 --> @@ -581,7 +581,7 @@ added: v0.5.3 The amount of bytes sent. -### socket.connect() +### `socket.connect()` Initiate a connection on a given socket. @@ -601,7 +601,7 @@ the error passed to the [`'error'`][] listener. The last parameter `connectListener`, if supplied, will be added as a listener for the [`'connect'`][] event **once**. -#### socket.connect(options\[, connectListener\]) +#### `socket.connect(options[, connectListener])` <!-- YAML added: v0.1.90 changes: @@ -677,7 +677,7 @@ net.connect({ }); ``` -#### socket.connect(path\[, connectListener\]) +#### `socket.connect(path[, connectListener])` * `path` {string} Path the client should connect to. See [Identifying paths for IPC connections][]. @@ -691,7 +691,7 @@ Alias to [`socket.connect(options[, connectListener])`][`socket.connect(options)`] called with `{ path: path }` as `options`. -#### socket.connect(port\[, host\]\[, connectListener\]) +#### `socket.connect(port[, host][, connectListener])` <!-- YAML added: v0.1.90 --> @@ -708,7 +708,7 @@ Alias to [`socket.connect(options[, connectListener])`][`socket.connect(options)`] called with `{port: port, host: host}` as `options`. -### socket.connecting +### `socket.connecting` <!-- YAML added: v6.1.0 --> @@ -723,7 +723,7 @@ that the [`socket.connect(options[, connectListener])`][`socket.connect(options)`] callback is a listener for the `'connect'` event. -### socket.destroy(\[exception\]) +### `socket.destroy([exception])` <!-- YAML added: v0.1.90 --> @@ -737,12 +737,12 @@ case of errors (parse error or so). If `exception` is specified, an [`'error'`][] event will be emitted and any listeners for that event will receive `exception` as an argument. -### socket.destroyed +### `socket.destroyed` * {boolean} Indicates if the connection is destroyed or not. Once a connection is destroyed no further data can be transferred using it. -### socket.end(\[data\[, encoding\]\]\[, callback\]) +### `socket.end([data[, encoding]][, callback])` <!-- YAML added: v0.1.90 --> @@ -758,7 +758,7 @@ server will still send some data. If `data` is specified, it is equivalent to calling `socket.write(data, encoding)` followed by [`socket.end()`][]. -### socket.localAddress +### `socket.localAddress` <!-- YAML added: v0.9.6 --> @@ -770,7 +770,7 @@ connecting on. For example, in a server listening on `'0.0.0.0'`, if a client connects on `'192.168.1.1'`, the value of `socket.localAddress` would be `'192.168.1.1'`. -### socket.localPort +### `socket.localPort` <!-- YAML added: v0.9.6 --> @@ -779,14 +779,14 @@ added: v0.9.6 The numeric representation of the local port. For example, `80` or `21`. -### socket.pause() +### `socket.pause()` * Returns: {net.Socket} The socket itself. Pauses the reading of data. That is, [`'data'`][] events will not be emitted. Useful to throttle back an upload. -### socket.pending +### `socket.pending` <!-- YAML added: v11.2.0 --> @@ -797,7 +797,7 @@ This is `true` if the socket is not connected yet, either because `.connect()` has not yet been called or because it is still in the process of connecting (see [`socket.connecting`][]). -### socket.ref() +### `socket.ref()` <!-- YAML added: v0.9.1 --> @@ -808,7 +808,7 @@ 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). If the socket is `ref`ed calling `ref` again will have no effect. -### socket.remoteAddress +### `socket.remoteAddress` <!-- YAML added: v0.5.10 --> @@ -819,7 +819,7 @@ The string representation of the remote IP address. For example, `'74.125.127.100'` or `'2001:4860:a005::68'`. Value may be `undefined` if the socket is destroyed (for example, if the client disconnected). -### socket.remoteFamily +### `socket.remoteFamily` <!-- YAML added: v0.11.14 --> @@ -828,7 +828,7 @@ added: v0.11.14 The string representation of the remote IP family. `'IPv4'` or `'IPv6'`. -### socket.remotePort +### `socket.remotePort` <!-- YAML added: v0.5.10 --> @@ -837,13 +837,13 @@ added: v0.5.10 The numeric representation of the remote port. For example, `80` or `21`. -### socket.resume() +### `socket.resume()` * Returns: {net.Socket} The socket itself. Resumes reading after a call to [`socket.pause()`][]. -### socket.setEncoding(\[encoding\]) +### `socket.setEncoding([encoding])` <!-- YAML added: v0.1.90 --> @@ -854,7 +854,7 @@ added: v0.1.90 Set the encoding for the socket as a [Readable Stream][]. See [`readable.setEncoding()`][] for more information. -### socket.setKeepAlive(\[enable\]\[, initialDelay\]) +### `socket.setKeepAlive([enable][, initialDelay])` <!-- YAML added: v0.1.92 --> @@ -871,7 +871,7 @@ data packet received and the first keepalive probe. Setting `0` for `initialDelay` will leave the value unchanged from the default (or previous) setting. -### socket.setNoDelay(\[noDelay\]) +### `socket.setNoDelay([noDelay])` <!-- YAML added: v0.1.90 --> @@ -883,7 +883,7 @@ Disables the Nagle algorithm. By default TCP connections use the Nagle algorithm, they buffer data before sending it off. Setting `true` for `noDelay` will immediately fire off data each time `socket.write()` is called. -### socket.setTimeout(timeout\[, callback\]) +### `socket.setTimeout(timeout[, callback])` <!-- YAML added: v0.1.90 --> @@ -912,7 +912,7 @@ If `timeout` is 0, then the existing idle timeout is disabled. The optional `callback` parameter will be added as a one-time listener for the [`'timeout'`][] event. -### socket.unref() +### `socket.unref()` <!-- YAML added: v0.9.1 --> @@ -923,7 +923,7 @@ Calling `unref()` on a socket will allow the program to exit if this is the only 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\]) +### `socket.write(data[, encoding][, callback])` <!-- YAML added: v0.1.90 --> @@ -946,7 +946,7 @@ written out, which may not be immediately. See `Writable` stream [`write()`][stream_writable_write] method for more information. -## net.connect() +## `net.connect()` Aliases to [`net.createConnection()`][`net.createConnection()`]. @@ -959,7 +959,7 @@ Possible signatures: * [`net.connect(port[, host][, connectListener])`][`net.connect(port, host)`] for TCP connections. -### net.connect(options\[, connectListener\]) +### `net.connect(options[, connectListener])` <!-- YAML added: v0.7.0 --> @@ -971,7 +971,7 @@ added: v0.7.0 Alias to [`net.createConnection(options[, connectListener])`][`net.createConnection(options)`]. -### net.connect(path\[, connectListener\]) +### `net.connect(path[, connectListener])` <!-- YAML added: v0.1.90 --> @@ -983,7 +983,7 @@ added: v0.1.90 Alias to [`net.createConnection(path[, connectListener])`][`net.createConnection(path)`]. -### net.connect(port\[, host\]\[, connectListener\]) +### `net.connect(port[, host][, connectListener])` <!-- YAML added: v0.1.90 --> @@ -996,7 +996,7 @@ added: v0.1.90 Alias to [`net.createConnection(port[, host][, connectListener])`][`net.createConnection(port, host)`]. -## net.createConnection() +## `net.createConnection()` A factory function, which creates a new [`net.Socket`][], immediately initiates connection with [`socket.connect()`][], @@ -1016,7 +1016,7 @@ Possible signatures: The [`net.connect()`][] function is an alias to this function. -### net.createConnection(options\[, connectListener\]) +### `net.createConnection(options[, connectListener])` <!-- YAML added: v0.1.90 --> @@ -1066,7 +1066,7 @@ changed to: const client = net.createConnection({ path: '/tmp/echo.sock' }); ``` -### net.createConnection(path\[, connectListener\]) +### `net.createConnection(path[, connectListener])` <!-- YAML added: v0.1.90 --> @@ -1087,7 +1087,7 @@ immediately initiates connection with [`socket.connect(path[, connectListener])`][`socket.connect(path)`], then returns the `net.Socket` that starts the connection. -### net.createConnection(port\[, host\]\[, connectListener\]) +### `net.createConnection(port[, host][, connectListener])` <!-- YAML added: v0.1.90 --> @@ -1110,7 +1110,7 @@ immediately initiates connection with [`socket.connect(port[, host][, connectListener])`][`socket.connect(port, host)`], then returns the `net.Socket` that starts the connection. -## net.createServer(\[options\]\[, connectionListener\]) +## `net.createServer([options][, connectionListener])` <!-- YAML added: v0.5.0 --> @@ -1184,7 +1184,7 @@ Use `nc` to connect to a Unix domain socket server: $ nc -U /tmp/echo.sock ``` -## net.isIP(input) +## `net.isIP(input)` <!-- YAML added: v0.3.0 --> @@ -1196,7 +1196,7 @@ Tests if input is an IP address. Returns `0` for invalid strings, returns `4` for IP version 4 addresses, and returns `6` for IP version 6 addresses. -## net.isIPv4(input) +## `net.isIPv4(input)` <!-- YAML added: v0.3.0 --> @@ -1206,7 +1206,7 @@ added: v0.3.0 Returns `true` if input is a version 4 IP address, otherwise returns `false`. -## net.isIPv6(input) +## `net.isIPv6(input)` <!-- YAML added: v0.3.0 --> |