const server = new net.Server(function (socket) { socket.on('message', (message) => { console.log(message) })})server.listen(8000)
connectionListener: Required, Type: Function.
Event: 'close'
Event: 'error'
Event: 'listening'
server.getAuthenticator()
Abstract method. Should be overridden to enable authentication.
Default:
server.getAuthenticator = function () { return null // Disable authentication}
Enable authentication:
const auth = new net.Auth('secretxxx')server.getAuthenticator = function () { return (signature) => auth.verify(signature)}
server.address()
Returns the bound address.
server.connections: RingPool
server.connections.length
Returns the number of concurrent connections on the server.
server.connections.next()
Return a socket in turn. Return null if no socket available.
server.close([callback])
Closes the server.
server.listen(...)
Same as node.js server.listen
Class toaNet.Client
Event: 'close'
Event: 'connect'
Event: 'auth'
Event: 'message'
Event: 'drain'
Event: 'end'
Event: 'error'
Event: 'timeout'
new toaNet.Client([options])
Creates RPC client.
const client = new net.Client().connect(8000)
options.retryDelay: Optional, Type: Number, Default: 500 ms.
Sets time interval for reconnection.
options.maxAttempts: Optional, Type: Number, Default: 50.
Sets max attempts for reconnection.
options.tcpTimeout: Optional, Type: Number, Default: 0.
Sets the socket to timeout after timeout milliseconds of inactivity on the socket.
options.tcpNoDelay: Optional, Type: Boolean, Default: true.
Disables the Nagle algorithm.
options.tcpKeepAlive: Optional, Type: Boolean, Default: true.
Enable/disable keep-alive functionality, and optionally set the initial delay before the first keepalive probe is sent on an idle socket.
client.connect(...)
Same as node.js socket.connect
client.connect('tcp://127.0.0.1:33333')
client.getSignature()
Abstract method. Should be overridden to enable authentication.
Default:
client.getSignature = function () { return '' // Disable authentication}
Enable authentication:
const auth = new net.Auth('secretxxx')client.getSignature = function () { return auth.sign({id: 'example'})}
client.request(method[, params])
Creates a JSON-RPC 2.0 request to another side. Returns thunk function.