A DDP server in C
We are developing a DDP server in the C language (don't ask why - we just need to). We've noticed that Meteor uses SockJS for its DDP protocol implementation. While there are libraries that allow me to do web sockets in C, I haven't found any SockJS libraries for C.
The SockJS library seems to be quite expansive and since there isn't a specification for how it operates, it sounds like a very brittle approach to try to reverse engineer its tricks.
It has left me wondering what the best strategies are for getting us to support DDP. There are few options I can think of:
- I could use SockJS library X for language Y and use Python/C / JNI / ... to interface with that
- Perhaps I could force Meteor to use web sockets only (the DDP docs seem to suggest this is possible, but I couldn't figure out how).
Option 3, if at all possible, would be the least effort, but would inherit the issues with WebSockets (browser interoperability, corporate firewalls etc.).
Option 1 and 2 are feasible, but the size of the library I'd have to include feels disproportionate to the functionality I would be using.
Considering the above, there doesn't seem to be a perfect solution. However I would like to validate the feasibility of the above options, and know whether I've missed something. Also, if someone tried this before, I'd love to hear about it.
I implemented an open source DDP server library in C++, that handles the protocol details. It should be used with some existing websocket library, such as mongoose, websocketpp, libwebsockets, etc.
So e.g. calling C++ methods from a MeteorJs site looks like this:
Getting live data from C++ also supported.
More information and examples - on GitHub:
We eventually decided to implement a subset of the SockJS protocol (http://sockjs.github.io/sockjs-protocol/sockjs-protocol-0.3.3.html) in C, using the Mongoose HTTP sserver (http://www.github.com/cesanta/mongoose).
The part of SockJS that negotiates with the server to verify whether web sockets are available is easy to implement. Additionally, the SockJS protocol wraps the web socket packages in its own header, and does liveliness checking with regular heartbeats.
Negotiation is done by responding to a sockjs/info request. The following response ensures that SockJS uses the web socket protocol:
The screenshot below shows the web socket traffic implemented so far with our SockJsServer & DDPServer: