Stability: 1 - Experimental
TCP Server for Callosum: a self-balancing distributed services protocol.
var CallosumServer = require('callosum-server-tcp');
var callosumServer = new CallosumServer({
host: 'localhost',
port: 4040
});
var CallosumServerSlots = require('callosum-server-slots');
var callosumServerSlots = new CallosumServerSlots();
callosumServer.on('connection', function (conn) {
// one of the active connections from clients that has been assigned a slot
// do stuff with `conn`
});
callosumServer.on('slot request', function (callback) {
return callback(null, callosumServerSlots.get());
});
callosumServer.on('slot free', function (slot) {
callosumServerSlots.put(slot);
});
callosumServer.listen(function () {
console.log('server listening...');
});
npm test
TCP Server for Callosum, which is an open-source implementation of Indeed's Boxcar: A self-balancing distributed services protocol.
When a new client connects to a TCP CallosumServer, the server will respond with the slot number assigned to the connection by sending a slot number followed by \r\n
. For example, for slot 13
:
13\r\n
This is all the information necessary for a client to either accept the slot, and keep the connection, or reject the slot by breaking the connection.
Public API
- CallosumServer.listen(options, [callback])
- new CallosumServer(options)
- callosumServer.close([callback])
- callosumServer.listen([callback])
- Event 'connection'
- Event 'error'
- Event 'slot free'
- Event 'slot request'
options
: Seenew CallosumServer(options)
options
.callback
: SeecallosumServer.listen(callback)
callback
.- Return: Object An instance of CallosumServer with server running.
Creates a new CallosumServer and starts the server.
options
: Objecthost
: String (Default: undefined) Hostname for the server to listen on. If not specified, the server will accept connections directed to any IPv4 address (INADDR_ANY
).port
: Integer (Default: 4040) Port number for the server to listen on.
Creates a new CallosumServer instance.
callback
: Function (Default: undefined)function () {}
Optional callback to call once the server is stopped.
Stops the server from accepting new connections.
callback
: Function (Default: undefined)function () {}
Optional callback to call once the server is up.
Starts the server to listen to new connections.
function (connection) {}
connection
: Socket object The connection object._slot
: Integer CAUTION: reserved for internal use The slot number assigned to this connection. Don't touch it.
Emitted once the connection is assigned a new slot via a callback
to the slot request
event.
function (error) {}
error
: Object An error that occurred.
Emitted when CallosumServer encounters an error. If no handler is registered, an exception will be thrown.
function (slot) {}
slot
: Integer Slot number to free.
Emitted when the a connection with previously assigned slot
is broken.
function (callback) {}
callback
: Functionfunction (error, slot) {}
The callback to call with the next available slot number.
Emitted when a new connection from a client is made.