使用网络库提供状态信息的 TCP 服务器

发布于 2024-10-16 23:44:24 字数 466 浏览 8 评论 0原文

我正在为在线回合制游戏编写 TCP 服务器。我已经使用 php 套接字编写了一个原型,但想转向 C++。我一直在研究流行的网络库(ASIO、ACE、POCO、LibEvent),但目前不清楚哪一个最适合我的需求:

1)连接是持久的(大约几分钟),并且服务器必须能够处理 100 多个并发连接。

2) 连接必须能够维护状态信息(用户登录信息)。 [我的 php 原型当前要求每个客户端请求包含登录信息]

3) 可选且最好是多线程,但单个进程。最好不要每个连接有 1 个线程,而是在所有打开的连接上使用固定数量的线程。


我倾向于 POCO 的 TCPServer 或 Reactor 框架,但不确定它们是否满足我的要求。我认为 Reactor 是单线程的,而 TCPServer 强制执行 1:1 线程/连接。我说得对吗?


无论哪种情况,我都不确定如何执行最重要的任务,将登录信息与随机进出的连接关联到特定连接。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜`诱少女 2024-10-23 23:44:24

Boost.Asio 应该可以满足您的要求。反应器队列可以由多个线程提供服务。使用异步方法将使您能够设计 为所有连接提供服务的固定线程数

教程示例可能是最好的起点。

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.

始于初秋 2024-10-23 23:44:24

您还可以看看 MUSCLE,这是我用它编写的一个多用户网络库和服务器考虑到这种应用程序。它获得 BSD 许可,可处理数百个用户,并包含一个服务器端数据库机制,用于存储和共享您希望客户端相互了解的任何信息。默认情况下,服务器是单线程的,但我在实践中没有发现这是一个问题(如果有必要,可以将服务器扩展为多线程)。

You might also take a look at MUSCLE, a multi-user networking library and server I wrote with this sort of application in mind. It's BSD-licensed, handles hundreds of users, and includes a server-side database mechanism for storing and sharing any information you want the clients to know about each other. The server is single-threaded by default, but I haven't found that to be a problem in practice (and it's possible to extend the server to be multithreaded if that turns out to be necessary).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文