Search code examples
c++pocoboost-asioace

TCP server with state information using network library


I'm writing a tcp server for an online turn-based game. I've already written a prototype using php sockets, but would like to move to C++. I've been looking at the popular network libraries (ASIO, ACE, POCO, LibEvent), but currently unclear which one would best suit my needs:

1) Connections are persistent (on the order of minutes), and the server must be able to handle 100+ simultaneous connections.

2) Connections must be able to maintain state information (user login info). [my php prototype currently requires each client request to contain the login info]

3) Optionally and preferably multi-threaded, but a single process. Prefer not to have 1 thread per connection, but a fixed number of threads working on all open connections.


I'm leaning towards POCO's TCPServer or Reactor frameworks, but not exactly sure if they meet my requirements. I think the Reactor is single threaded, and the TCPServer enforces 1:1 threading/connection. Am I correct?


In either case case, I'm not exactly sure how to do the most important task of associating login info to a specific connection with connections coming and going at random.


Solution

  • Boost.Asio should meet your requirements. The reactor queue can be serviced by multiple threads. Using asynchronous methods will enable your design of a fixed number of threads servicing all connections.

    The tutorials and examples are probably the best place to start if you are unfamiliar with the library.