Tuesday 10 January 2012

Non blocking C++ Ajax bridge code generator

I have come to the conclusion that writing Ajax web services in C++ is really painful.  First you need to know the http protocol, C++ and Javascript, secondly you need to design your own communication protocol on top of that marshals json messages to and from the web browser, third you need to design it so that it does not gobble up tonnes of threading resources, forth you need to make it secure and you need to make it fast.
There are tools for this GSOAP is a great library for communicating via soap but not to web clients, yes you can communicate between SOAP and javascript clients, but SOAP is so unfriendly and inefficient there should be something better.  You can use the open source json libraries and make your own http stack.  A great library to use is the ASIO library for communicating in a non blocking way, but there is no code generator to work with it.
I have therefore written my own code generator that parses C++ headers and produces the necessary C++ and javascript over the ASIO library.  It is fast and non blocking, so that it will process network packets as they arrive and then return to the event queue to wait for the next network packet to complete the message.
My next step is to make it work over web sockets transparently, degrading back to long polling for clients to be able to recieve events generated by the server.
If there is anyone who wants to try out a beta version of this generator then please let me know.

No comments:

Post a Comment