I need to create a network server in C++ for a trading application. This network server needs to perform the following tasks:
handle authentication of clients and provide session id for each session.
handle orders originating from the clients a开发者_StackOverflow中文版nd inform clients about their execution.
handle other data request asked for by the clients and send data back to them.
I am planning to use Boost.Asio networking library and Google protocol buffers to implement the messages being sent from the clients to the server. XML-RPC or SOAP based approaches are a strict no-no as latency is a big concern.
I have the following questions for the stackoverflow community:
Is it a good idea to implement these messages using protocol buffers? I am also considering sending messages Boost serialization library to implement this. When I look at the code, I find myself more confident of implementing this with boost serialization and Google protobuf headers look too heavyweight. Which of these methods will be a) more maintainable and b) require less effort? I guess, both these approaches will work across different platforms.
Is there any other networking library which I should look at apart from Boost.Asio.?I find ACE a little dated as far as C++ coding style is concerned.
Eventually I would like to make this network server run on SSL, however, I do not have any experience with implementing SSL. How much effort would it require to move to SSL later on. Should I start with SSL or can it be added later on?
Does anybody know of a good open source network project, which might have implemented a similar network server using Boost.Asio, to get inspired from?
You should also look at Apache Thrift (originated at Facebook) or Apache Etch (initially developed by Cisco). They are RPC frameworks that make it easy to develop both servers and clients meeting your needs (more or less). For a framework developed using protobuf and boost.asio, look at the server1 project.
BSON ( http://www.mongodb.org/display/DOCS/BSON and http://bsonspec.org ) is a very fast binary protocol. C++ implementation is readily available from mongodb. The fact that it is basically JSON makes it quite easy to implement and maintain.
SSL implementation doesn't add up much extra code to the asio-based server: SSL context initialization with certificate paths and some handshake logic.
You should look into MessagePack http://msgpack.org/
If you are allowed to purchase off the shelf library for networking then take a look at JetBytes Server Framework for your networking needs. I remember reading that it did the heavy lifting for the PayPoint. Len Holgate (the man behind the company and the library) is active on these forums to.
Take a look into www.zeromq.org
It's is not exactly what you asked, but it is something that will definitively solve your problem and speed up your development.
zeromq is a lightweight message queue, with a lot of different transports, and it has bindings for a lot of languages.
It is also used in a lot of trading servers.
I'm kinda late to the party - but I wanted to throw POCO (http://pocoproject.org/) into the ring as well. I wont say it is better than ASIO (because it isn't) but it is as good. And if you are not a template god - you will find POCO delightful. Definitely a better bet than ACE which is getting a little long in the tooth.
following tasks:
- handle authentication of clients and provide session id for each session.
If you have SSL from the beginning then you can have server and client auth which would cover this task without having to add additional custom auth to your client/server apps.
精彩评论