C/C++ 中的简单广播库/示例

发布于 2024-11-05 00:37:35 字数 440 浏览 1 评论 0 原文

我正在组装一个用 C/C++ 编写的客户端/服务器应用程序。它主要是 C 语言,带有一些 C++ 功能 - 我来自 C 和 Java 世界,不使用大量高级 C++ 语言功能。无论如何,服务器驻留在一台计算机上并进行各种内部计算,并且一天几次(在不可预测的时间)它会将信息广播到一定数量的已在服务器上注册的客户端(驻留在其他计算机上)收听此类广播消息。服务器必须能够 100% 可靠且非常快速地向所有注册客户端广播,以便客户端可以更新自己的内部数据以反映服务器中的状态更改 - 服务器刚刚向它们广播的状态更改。由于它必须可靠,因此它必须是 TCP/IP,而不是 UDP。

这似乎是 C++ 中网络的一个相当标准的体系结构,但我想找到一个好的库,可以让我轻松地完成此操作(WinSock 库的某种包装器,以便我可以在 Windows 上轻松完成此操作,而无需深入研究 WinSock 的具体怪癖)以及一个如何做此类事情的简单示例。

谢谢。

I'm putting together a client/server application written in C/C++. It is mostly C with some C++ features - I come from the C and Java world and don't use lots of heavy advanced C++ language features. In any case, the server resides on one computer and does a variety of internal calculation, and several times a day (at unpredictable times) it will broadcast information to some number of clients (residing on other computers) that have registered with the server to listen for such broadcast messages. The server must be able to broadcast to all registered clients with 100% reliability and very quickly so that clients can update their own internal data to reflect the state change in the server - the state change that the server just broadcast to them. Since it must be reliable, it would have to be TCP/IP, not UDP.

This seems like a pretty standard architecture for networking in C++, but I'd like to find a good library that would allow me to do this easily (some sort of wrapper for the WinSock library so that I can do it easily on Windows without having to dig in to the specific quirks of WinSock) and a simple example of how one would do this sort of thing.

Thanks.

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

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

发布评论

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

评论(3

夏の忆 2024-11-12 00:37:35

查看 boost::asio。他们的示例可以在这里找到: http://www.boost .org/doc/libs/1_38_0/doc/html/boost_asio/examples.html

它抽象了大多数特定于平台的怪癖,以便您可以快速开始工作。

Check out boost::asio. Their examples are available here: http://www.boost.org/doc/libs/1_38_0/doc/html/boost_asio/examples.html

It abstracts most platform-specific quirks so you can get down to business quickly.

万劫不复 2024-11-12 00:37:35

有两个来自自由开源世界的 C/C++ 网络通信库 - LibEventBoost.Asio。使用它们,您无需深入了解操作系统的细节或用于网络通信的特定 API。他们都有很好的文档和一组不错的 示例< /a>.

附带说明一下,从更高的角度来看,即使使用 TCP/IP 也不能使通信协议变得可靠。为了提供可靠性,应用程序通常在 TCP/IP 之上定义更高级别的协议。这些协议描述了消息的排序、心跳、重传支持等。还有建立在 UDP 之上的可靠协议(所谓的 RUDP)。

如果您觉得速度和可靠性非常重要,您可能需要使用行业领先的技术之一,例如 Tibco、LBM (Informatica/29West) 或 特维拉。所有这些解决方案都可以在不同的通信协议之上工作,同时为用户提供无缝的 API。

There are two libraries for C/C++ network communications from free and open-source world that rock - LibEvent and Boost.Asio. Using them you won't need to dig into specifics of the operating system, or specific APIs for network communications. They both have a good documentation and a set of decent examples.

As a side note, even using TCP/IP doesn't make the communication protocol reliable from the higher point of view. In order to provide reliability, applications usually define higher-level protocols on top of TCP/IP. Those protocols describe sequencing of the messages, heartbeats, retransmission support etcetera. There are also reliable protocols built on top of UDP (so-called RUDP).

If you feel like speed and reliability is very important, you may want to use one of the industry leading technologies, such as Tibco, LBM (Informatica/29West), or Tervela. All of those solutions can work on top of different communication protocols while providing seamless API for the user.

隔纱相望 2024-11-12 00:37:35

这将需要大量的 C++ 功能(模板等),但是 boost::asio 非常出色,正是您完成此任务所需要的。然而,它显然需要一些时间来适应,因为编程模型与直接的 C++ 有很大不同。该网站上有非常好的文档和大量示例。

This will require a decent amount of C++ features (templates, etc) but boost::asio is excellent and exactly what you need for this task. However, it'll clearly require some getting used to, as the programming model is quite different from straight C++. There is pretty good documentation and lots of examples at the site.

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