Skip to content

Transports

Frederic Charette edited this page Apr 12, 2017 · 6 revisions

What are they

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.

Custom transports

Building your own transport is somewhat easy. You simply need to implement these interfaces:

Listen

/**
 * 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) {}
``̀ 

### Stop

```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) {}
`

### getOrigin

```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) {}
``̀ 

### createSocket

```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) {}
`

### attachSocket

```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) {}

send

/**
 * 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) {}

disconnect

/**
 * 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) {}
Clone this wiki locally