问题
I'll be quick and honest: I'm currently trying to write a client/server for an online game. Since I'm poor and limited on resources, I'll be testing the bare basics of the server using a PHP backend, with the eventual goal being to rebuild the server end in C++.
I'm looking for a C++ library for Windows (XP and Vista preferably) that will let me use a finite number of threads, one dedicated to each piece of the networking problem. As an example, I want to use a thread to report the positional information of the player to the server (and to receive responses about positional information of the other players) but I want a different thread to background download in the 3D artwork for the area/players, and a different thread for the built in chat system, etc. These all need to be fairly independent of one another.
I know what I want to do with the library, I've got the design bit figured out, I just feel a bit silly re-inventing the wheel, since I know that a good library for this exact purpose probably already exists. So, what are your suggestions? I need to be able to send data to a server, and accept responses. Ideally, the request needs to trigger an Event when its done (so I can immediately grab the data and do something with it) and I need to be able to handle multiple transactions simultaneously. HTTP is a nice bonus, but I can handle HTTP protocol myself if necessary, especially considering that I plan on dropping it in the long run.
Thanks!
回答1:
Boost.Asio
ASIO has simple web server examples.
Boost.Thread
回答2:
You can try the POCO library. It has a multithreaded TCP server and a HTTPserver.
回答3:
Check out the Boost libraries, in particular, Boost Threads.
回答4:
You can try my CSocksetServer class. It can handle many connections in separate threads and supplies you with lots of different events. While it doesn’t have native HTTP capabilities, I have built web servers with it.
回答5:
You should just use cUrl with multihandles. It is better designed to do what you want than whatever it is that you have designed.
来源:https://stackoverflow.com/questions/342918/simple-asynchronous-multi-threaded-http-request-library-for-c