在C ++中通过http帮助流 [英] Help streaming over http in C++

查看:149
本文介绍了在C ++中通过http帮助流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用提供流式API的网络服务。这个api通常可以由java方法java.net.URL.openStream();

I'm looking to use a web service that offers a streaming api. This api can typically be used by the java method java.net.URL.openStream();

使用问题是我试图在C ++中设计我的程序,什么库(我听说过cUrl库非常好这种东西)使用,或如何使用他们做我想要的。

Problem is I am trying to design my program in C++ and have no idea what libraries (I've heard the cUrl library is very good at this sort of thing) to use, or how to use them to do what I want.

是在将文件作为流打开后,我可以实时访问持续更新数据。

The idea is that after opening the file as a stream I can access continually updating data in realtime.

任何帮助将非常感激。

推荐答案

Boost.Asio 套接字iostreams似乎是你的后。您的代码将如下所示:

Boost.Asio socket iostreams seem to be what you're after. Your code will look like this:

ip::tcp::iostream stream("www.someserver.com", "http");
if (!stream)
{
  // Can't connect.
}

// Use stream as a regular C++ input stream:
std::string text;
std::getline(stream, text);

如果你刚接触C ++,没有iostreams的经验,那么此页面是一个很好的信息来源。特别是,检查 istream 类的文档,看看你的Boost.ASIO流将支持什么样的操作。 您会发现它们与Java IO API中没有那么大不同。

If you're new to C++ and have no experience with iostreams then this page is an excellent source of information. In particular, check the docs of the istream class to see what kind of operations your Boost.ASIO stream will support. You'll find that they're not so different from those in the Java IO API.

编辑:

Eric是对的,你必须向服务器发送一些请求(使用同一个流),所以它可能不像我以前想的那样类似于Java的 openStream 。以下示例说明如何提出这些请求:

Eric is right, you'll have to send some requests to the server (using the same stream) so it's probably less similar to Java's openStream than I thought. The following example shows how to make those requests:

http://blog.think-async.com/2007_01_01_archive.html

这篇关于在C ++中通过http帮助流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆