从 C++ 发送数据的最佳方式编程到 Rails 服务器
我有一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
套接字是必经之路。如果你想要一些好的 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.
您可以按照您想要的方式存储数据(文件或数据库)。
唯一的难点是让您的 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.
您可以使用套接字,因为您的两个程序都驻留在同一台本地计算机上,并且通常通过本地套接字发送序列化数据应该非常简单。由于套接字使用内部缓冲区,因此传输时间应该非常快。您的 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.