Simple Asynchronous Multi-Threaded HTTP request li

2019-05-11 02:21发布

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!

5条回答
唯我独甜
2楼-- · 2019-05-11 02:43

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.

查看更多
▲ chillily
3楼-- · 2019-05-11 02:52

You can try the POCO library. It has a multithreaded TCP server and a HTTPserver.

查看更多
手持菜刀,她持情操
4楼-- · 2019-05-11 02:57

You should just use cUrl with multihandles. It is better designed to do what you want than whatever it is that you have designed.

查看更多
小情绪 Triste *
5楼-- · 2019-05-11 02:59

Check out the Boost libraries, in particular, Boost Threads.

查看更多
男人必须洒脱
6楼-- · 2019-05-11 03:01

Boost.Asio

ASIO has simple web server examples.

Boost.Thread

查看更多
登录 后发表回答