-
-
Notifications
You must be signed in to change notification settings - Fork 10
Transports
Frederic Charette edited this page Apr 11, 2017
·
6 revisions
Transports are the interfaces between protocol implementations and Kalm.
The 3 bundled transports present in Kalm by default are IPC
, TCP
and UDP
.
See this flowchart to see where they tie in.
Building your own transport is somewhat easy. You simply need to implement these interfaces:
/**
* This starts listening for connections based on the configs and triggers the handlers accordingly
* @param {object} handlers The server's private event hooks (handleConnection, handleError)
* @param {object} options The options for the server
* @returns {Promise} A promise that resolves with the protocol's listener handle when it is ready
*/
function listen(handlers, options) {}
``̀
```node
/**
* This attempts to shut down the listener
* @param {object} server An instance of Kalm server. Which includes the (listener) property
* @param {function} callback The optional callback method, when the server is down
*/
function stop(server, callback) {}
``̀
```node
/**
* This attempts to retrieve the origin of a given client
* @param {object} socket An instance of the protocol's client object
* @returns {object} An object that includes an 'host' and 'port' property
*/
function getOrigin(socket) {}
``̀
```node
/**
* This creates an instance of a client in the protocol layer and returns it
* @param {object} client A Kalm client object
* @returns {object} An instance of the protocol's client object
*/
function createSocket(client) {}
``̀
```node
/**
* This binds the internal event hooks of the Kalm client to the events of the protocol's client (socket)
* @param {object} socket An instance of the protocol's client object
* @param {object} handlers A collection of internal event hooks (handleRequest, handleError, handleConnect, handleDisconnect)
*/
function attachSocket(socket, handlers) {}
/**
* Instructs the protocol's client to send a payload
* @param {object} socket An instance of the protocol's client object
* @param {Buffer} payload The binary data to send
*/
function send(socket, payload) {}
/**
* Kills a protocol's client
* @param {object} client An instance of a Kalm client with the (socket) property
* @param {function} callback The optional callback method, when the client is down
*/
function disconnect(client, callback) {}