Networking abstractions for heldb.
Transportation:
setTimeout)const server = require('require/server')({
local: {}
})
server.start({
ready () {
}
connection (socket) {
}
})
const socket = require('helnet/socket')({
sessionId: 'id' + Math.random(),
local: {
server
}
})
socket.start({
ready () {
}
message (message) {
}
unreliableMessage (message) {
}
close () {
}
})
const socket = require('helnet/socket')(spec)Creates a new socket connection to a given server. An exception is raised if the configuration is invalid.
spec.sessionIdA unique string identifying the session of the client.
spec.localspec.local.server a local server server instancesocket.sessionIdThe socket's unique sessionId variable.
socket.openBoolean flag. If true, socket can accept send events.
socket.start(spec)Starts the socket. spec is a dictionary of callbacks with the following properties:
spec.read(err) called when the socket is readyspec.message(data) called when the socket recieves a messagespec.unreliableMessage(data) called when the socket receives an unreliable messagespec.close(err) called when the socket closessocket.send(message)Sends a reliable, ordered message to the client.
socket.sendUnreliable(message)Sends a message unreliably to the server. This message may be dropped or reordered.
socket.close()Closes the socket connection
const server = require('helnet/server')(spec)Constructs a new server object
spec.localserver.clientsAn array of all currently connected clients
server.openIf true then server is open
server.start(spec)spec.ready(err)spec.connection(socket) called when a client connects. socket is an instance of a socket like aboveserver.close()Closes the server