diff --git a/doc/api/net.md b/doc/api/net.md index 7ec75e358f396a..2d4ca5383fe803 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` @@ -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'` @@ -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'` @@ -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'` @@ -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'` Emitted when the server has been bound after calling [`server.listen()`][]. -### server.address() +### `server.address()` @@ -142,7 +142,7 @@ server.listen(() => { Don't call `server.address()` until the `'listening'` event has been emitted. -### server.close(\[callback\]) +### `server.close([callback])` @@ -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` @@ -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])` @@ -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])` @@ -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])` @@ -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` * {boolean} Indicates whether or not the server is listening for connections. -### server.maxConnections +### `server.maxConnections` @@ -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()` @@ -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()` @@ -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` @@ -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])` @@ -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'` @@ -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'` @@ -446,7 +446,7 @@ added: v0.1.90 Emitted when a socket connection is successfully established. See [`net.createConnection()`][]. -### Event: 'data' +### Event: `'data'` @@ -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'` @@ -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'` @@ -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'` @@ -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'` @@ -520,7 +520,7 @@ Emitted when a socket is ready to be used. Triggered immediately after `'connect'`. -### Event: 'timeout' +### Event: `'timeout'` @@ -530,7 +530,7 @@ the socket has been idle. The user must manually close the connection. See also: [`socket.setTimeout()`][]. -### socket.address() +### `socket.address()` @@ -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` @@ -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` @@ -572,7 +572,7 @@ added: v0.5.3 The amount of received bytes. -### socket.bytesWritten +### `socket.bytesWritten` @@ -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])` @@ -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` @@ -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])` @@ -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])` @@ -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` @@ -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` @@ -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` @@ -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()` @@ -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` @@ -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` @@ -828,7 +828,7 @@ added: v0.11.14 The string representation of the remote IP family. `'IPv4'` or `'IPv6'`. -### socket.remotePort +### `socket.remotePort` @@ -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])` @@ -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])` @@ -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])` @@ -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])` @@ -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()` @@ -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])` @@ -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])` @@ -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])` @@ -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])` @@ -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])` @@ -1066,7 +1066,7 @@ changed to: const client = net.createConnection({ path: '/tmp/echo.sock' }); ``` -### net.createConnection(path\[, connectListener\]) +### `net.createConnection(path[, connectListener])` @@ -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])` @@ -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])` @@ -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)` @@ -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)` @@ -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)`