Net

Node.js net module — TCP and IPC networking primitives.

Module: node:net Support: Experimental Since: 1.1.0 Docs: Node.js Docs

Static Methods

🟢 createConnection(options, host, connectListener)
Creates a new TCP connection and returns the connected Socket.
🟢 connect(options, host, connectListener)
Options for establishing a TCP or IPC socket connection.
🟢 createServer(options, connectionListener)
Creates a new TCP server.
🟢 isIP(input)
Tests whether the input is a valid IP address (v4 or v6).
🟢 isIPv4(input)
Tests whether the input is a valid IPv4 address.
🟢 isIPv6(input)
Tests whether the input is a valid IPv6 address.

Dictionary SocketConnectOptions

Options for establishing a TCP or IPC socket connection.

Since: 1.1.0 Docs: Node.js Docs

6 members: 1 supported, 5 undocumented

Properties

🟢 port
Options for establishing a TCP or IPC socket connection.
⚪ host
Hostname or IP address (default: "localhost").
⚪ localAddress
Local address to bind the socket to.
⚪ localPort
Local port to bind the socket to.
⚪ family
Local port to bind the socket to.
⚪ lookup
IP address family (4 or 6).

---

Interface Socket

A TCP or IPC socket implementing the duplex stream interface.

Extends: Duplex Implements: EventEmitter Since: 1.1.0 Docs: Node.js Docs

18 members: 15 supported, 3 undocumented

Constructors

🟢 constructor(options)
Supported

Methods

🟢 connect(options, host, connectListener)
Options for establishing a TCP or IPC socket connection.
🟢 destroy(error)
Half-closes the socket and destroys it with an optional error.
🟢 setTimeout(timeout, callback)
Sets an inactivity timeout on the socket.
🟢 setNoDelay(noDelay)
Enables or disables Nagle's algorithm.
🟢 setKeepAlive(enable, initialDelay)
Enables or disables TCP keep-alive.
🟢 ref()
Keeps the event loop alive while this socket is open.
🟢 unref()
Allows the event loop to exit even while this socket is open.
⚪ address()
TCP port number to connect to.

Properties

🟢 remoteAddress
— Remote IP address of the connected peer.
🟢 remoteFamily
— Address family of the remote peer ("IPv4" or "IPv6").
🟢 remotePort
— Remote TCP port.
⚪ localAddress
Local address to bind the socket to.
⚪ localPort
Local port to bind the socket to.
🟢 bytesRead
— Total bytes received on this socket.
🟢 bytesWritten
— Total bytes sent on this socket.
🟢 connecting
— Total bytes sent on this socket.
🟢 pending
— True if the socket is not yet connected.

---

Interface NetServer

A TCP server that accepts incoming socket connections.

Extends: EventEmitter Implements: EventEmitter Since: 1.1.0 Docs: Node.js Docs

9 members: 8 supported, 1 undocumented

Constructors

🟢 constructor(options, connectionListener)
Supported

Methods

🟢 listen(port, host, backlog, callback)
Begins accepting connections on the specified port and host.
🟢 close(callback)
Stops accepting new connections.
⚪ address()
TCP port number to connect to.
🟢 getConnections(callback)
Returns the number of currently open connections.
🟢 ref()
Keeps the event loop alive while this socket is open.
🟢 unref()
Allows the event loop to exit even while this socket is open.

Properties

🟢 listening
Allows the event loop to exit even while this server is active.
🟢 maxConnections
— Maximum number of simultaneous connections allowed.

---