从 C++ 发送数据的最佳方式编程到 Rails 服务器

发布于 2024-11-16 03:47:24 字数 100 浏览 6 评论 0原文

我有一个 C++ 程序,它不断生成大量需要发送到 Rails 服务器的数据。程序和服务器都在运行 Suse Linux 的同一台机器上。

最有效、最简单的解决方案是什么?

I have a C++ program that is constantly generating a large amount of data that needs to be sent to a Rails server. Both the program and the server are on the same machine running Suse Linux.

What is the most efficient and simple solution for this?

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

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

发布评论

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

评论(3

抹茶夏天i‖ 2024-11-23 03:47:24

套接字是必经之路。如果你想要一些好的 C++ 异步和跨平台套接字,你最好的选择可能是 boost::asio。

Sockets are the way to go. If you want some good asynchronous and cross-platform sockets in C++ your best bet, probably, will be boost::asio.

我一向站在原地 2024-11-23 03:47:24

您可以按照您想要的方式存储数据(文件或数据库)。

唯一的难点是让您的 Rails 应用程序知道 C++ 程序已完成。
我强烈建议您将此信息存储在缓存中,这样每次需要时检查此信息就不会花费太多。

You could store the data the way you want (file or database).

The only tough point is to make your Rails app aware the C++ program is completed.
I'd strongly advise you to store this information in cache so that it won't cost much to check this every period you need.

迷迭香的记忆 2024-11-23 03:47:24

您可以使用套接字,因为您的两个程序都驻留在同一台本地计算机上,并且通常通过本地套接字发送序列化数据应该非常简单。由于套接字使用内部缓冲区,因此传输时间应该非常快。您的 C++ 程序可以将数据推送到 Rails 服务器,也可以让 Rails 服务器轮询 C++ 程序,前提是您在 C++ 程序中设置缓存以在轮询调用之间存储数据。不过,推送方法可能效果最好。

You could use sockets since both your programs are residing on the same local machine, and in general it should be pretty straight-forward to send the serialized data over a local socket. Since the socket is using an internal buffer, the transfer time should be very fast. Your C++ program can either push data to the Rails server, or you can have the Rails server poll the C++ program providing you're setting up a cache in your C++ program to store the data in between polling calls. The push method would probably work best though.

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