Hailing Frequencies Open: NodeFly Introduces Uhura

NodeFly is pleased to introduce Uhura to the Node.js universe. Uhura is a two-way client/server event emitter that is similar to the emitter in Socket.IO, but excludes the extra bits like multiple transports and rooms.

How does Uhura work? It simply converts events into json string fragments and writes them to a stream. Currently it is strapped onto a TCP connection stream, but it could actually be strapped onto any stream. The TCP logic includes some basic event buffering, along with reconnection logic with an exponential backoff mechanism. It also hijacks the session store system in connect to allow maintaining a shared data store between the client and server. Anything stored on one side is automatically synchronized to the other side.

image

Socket.IO works well enough for browser/server communication, but it doesn’t meet NodeFly’s requirements when it comes to server-server communication. The root cause is not Socket.IO but ws, the websocket module it depends on. It has several edge cases where it may throw errors that are very tricky to catch, and as things scale, the frequency of these errors increase. Socket.IO was also overkill for our needs. We don’t require multiple transports, we don’t need rooms, and we don’t need the extra overhead of the WebSocket protocol. We just needed a constant stream of json events from one server to another, stable code, with automatic reconnection and event buffering while disconnected.

So we built our own simplified equivalent that works for our needs.  To take advantage of Uhura ensure that you are using the version tagged ‘stable’. 

Where’s the code?

It’s pretty simple to use, just create a server and connect some clients. The repo is at:

https://github.com/NodeFly/uhura

 

    var server = Uhura.createServer(function (client) {

        client.on(‘ping’, function () {

            console.log(‘foo is’, client.get(‘foo’))

            client.send(‘pong’)

        })

    })

    server.listen(5555)

   

    var client = Uhura.createClient(5555)

    client.on(‘connect’, function () {

        client.set(‘foo’, ‘bar’)

        client.on(‘pong’, function () {

            console.log(‘pong received’)

        })

        client.send(‘ping’)

    })

 

Our agent is making the most of Uhura, to allow you to make the most of our agent. If you are not yet using it, try it out at:

http://www.nodefly.com