Constructor
new Server() → {Server}
Creates a new Server instance.
Fires:
- event:listening - Emitted when the server has been bound.
- event:connection - Emitted when a new connection is made.
- event:close - Emitted when the server stops accepting new connections.
- event:error - Emitted when an error occurs.
Returns:
- Type:
-
Server
An instance of the TCP Server
class.
Methods
accept() → {Promise.<Socket>}
Waits for a TCP client to connect and accepts the connection.
Returns:
- Type:
-
Promise.<Socket>
- A
Socket
object representing the connected client.
address() → {SocketHost}
Returns the bound address, the address family name and port of the socket.
Returns:
- Type:
-
SocketHost
The host information where the server is listening.
(async) listen(port, host) → {Promise.<SocketHost>}
Starts listening for incoming connections.
Parameters:
Name | Type | Description |
---|---|---|
port |
string
|
number
|
The port number or string on which the server should listen. |
host |
string
|
The hostname or IP address on which the server will listen. |
Returns:
- Type:
-
Promise.<SocketHost>
The host information where the server is listening.