Server

Server

A mock server socket, more-or-less like net.Server.

Constructor

new Server(optionsopt, connectionListeneropt)

Creates an instance of Server.
Source:
Parameters:
Name Type Attributes Description
options ServerOpts | SocketCallback <optional>
Options for the server.
connectionListener SocketCallback <optional>
Register this as the event listener for the 'listening' event, if provided.

Classes

Server

Methods

_checkClosed()

If all of the clients have closed, clean up and emit the 'close' event.
Source:

close(cbopt) → {Server}

Close down all of the clients, then the server.
Source:
Parameters:
Name Type Attributes Description
cb PlainCallback <optional>
Registered as listener for the 'close' event.
Returns:
Type:
Server
This.

emit(eventName, …args) → {boolean}

Add debug logging to EventEmitter. Start with NODE_DEBUG=mock-tls-server to see all events.
Source:
Parameters:
Name Type Attributes Description
eventName string The name of the event.
args Array.<any> <repeatable>
The arguments to be passed to listeners.
Returns:
Type:
boolean
Returns `true` if the event had listeners, `false` otherwise.

getConnections(cb) → {Server}

Get the number of current clients.
Source:
Parameters:
Name Type Description
cb CountCallback Called with the current number of clients.
Throws:
Callback not a function.
Type
TypeError
Returns:
Type:
Server
This.

listen(optionsopt, listeningListeneropt) → {Server}

Listen for incoming connections. Whenever `connect` is called on this server's port, create a mock socket wrapped in a TLSSocket.
Source:
Parameters:
Name Type Attributes Description
options number | ListenOptions <optional>
Port number or options object.
listeningListener function <optional>
If it exists, installed as a listener for the 'listening' event.
Returns:
Type:
Server
This.