Net

TCP Networking APIs

The TCP Networking APIs provide an asynchronous network API for creating stream-based TCP servers and clients.

Classes

Server
Socket

Members

(static, constant) connect

Aliases to net.createConnection().

Additional signatures:

  • connect(port: number | string, host?: string)
Source:

Methods

(static) createConnection(options) → {Socket}

Initiates a connection to a given remote host.

Additional signatures:

  • createConnection(port: number | string, host?: string)
Source:
Parameters:
Name Type Description
options Object

Configuration options for the connection.

Name Type Description
host string

The hostname or IP address of the remote server to connect to.

port string | number

The port number on the remote host to connect to.

Returns:
Type:
Socket

An instance of the Socket class

(static) createServer(onConnectionopt) → {Server}

Creates a new TCP server.

Source:
Parameters:
Name Type Attributes Description
onConnection function <optional>

A function that is called whenever a connection is made to the server.

Returns:
Type:
Server

An instance of the Server class.

Type Definitions

SocketHost

Information about the host TCP socket.

Properties:
Name Type Description
port number

The port number on the local machine.

family string

The IP family of the local address (IPv4 or IPv6).

address string

The local IP address.

Source:

SocketRemote

Information about the remote TCP socket.

Properties:
Name Type Description
port number

The port number on the remote machine.

address string

The remote IP address.

Source:

socketInfo

Information about the connected TCP socket.

Properties:
Name Type Description
host SocketHost

Information about the local endpoint of the socket.

remote SocketRemote

Information about the remote endpoint of the socket.

Source: