How does the socket server framework compare to Boost::ASIO?

I’ve had a few questions from users and potential users of The Server Framework about how it compares to other available frameworks. One such framework is ASIO.

The first thing to realise is that The Server Framework and ASIO are very different both in design and functionality. ASIO’s strengths are that it’s cross platform, it provides low-level asynchronous I/O and that it uses a modern C++ design (i.e. lots and lots of templates and ‘interesting’ call stacks). The Server Framework is purely for Windows (and even then only those variants of Windows that are descended from the Windows NT line). The Server Framework provides a much higher level of abstraction and the abstractions are aimed at the problem space whereas, IMHO, the ASIO abstractions are aimed at the solution space (i.e. lots of boost-style clever C++ techniques). And finally, The Server Framework uses slightly more old fashioned C++ concepts, we have lots of objects, lots of interfaces and very few templates. As such whilst it’s certainly possible to build the same kinds of servers with both frameworks you need to do more of the design and implementation to build robust scalable servers for the Windows platform if you start with ASIO.

ASIO’s documentation contains several simple examples, but, to be honest, the key word here is simple. It’s interesting to see that you can build a single- threaded, overlapped I/O server for multiple platforms but once you start to move away from this design you’re pretty much on your own. Sure there’s a server example that uses a pool of threads to run the overlapped I/O but there’s little in the way of documentation about how or why you might want to do this and you’re left having to build the thread pool and whatever else you need yourself. Likewise, whilst there are hints that you can provide reference counted buffers and custom buffer and connection allocators there are no complete examples and so you’ll have to craft these yourself. Finally the examples are presented as a collection of files, you need to provide your own project or makefile (which is understandable given the number of platforms that ASIO supports and the fact that the compile environments are unlikely to be standardised). In comparison The Server Framework has lots of well documented example servers each of which builds on previous server examples to add particular items of functionality. All of the examples build in all versions of Visual Studio from VC6 through to VS2008 and as both x86 and x64 native executables in VS2005 and VS2008. Our basic echo server example assumes that the servers that you’ll be writing will be more complex and more scalable than the simple servers that anyone can write with thread-per-connection style synchronous socket calls and the subsequent examples give users a way to select an example that is a near fit for what they want to achieve and use that as a starting point.

There are some things that I find really interesting in ASIO and these include that it’s very easy to write simple clients that connect to TCP servers and allow you treat them as if they were a C++ style stream of data. The ‘read_until’ stuff that uses a regex to perform byte stream message splitting is nice and the concept of ‘strands’ is interesting; ‘strands’ allow you to ensure that for a given connection you’ll only ever have one event handler operating at a time.

Overall I think that ASIO’s strengths are also its weaknesses. If cross platform, low-level or modern C++ techniques are high on your list of requirements then ASIO is for you. If these things are not as important and you need to target Windows and want to write a high performance, robust, scalable server quickly then perhaps the higher level of abstraction that The Server Framework provides is more appropriate; alternatively, read my blog, understand all of the nitty, gritty issues that you need to address with highly scalable servers on Windows and solve these problems in your ASIO server ;)