升压,使用TCP,prefered方法通过网络发送的文件吗? [英] Boost, sending files over the network using tcp, prefered method?

查看:184
本文介绍了升压,使用TCP,prefered方法通过网络发送的文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在文档中的升压的例子,TCP:iostream的使用非常简单地发送数据流在网络上。在其它的例子写的()用于将数据写入到插座,而不是参与多一点code。

In the boost examples in the documentation, tcp:iostream is used to very simply send streams over the network. In other examples write() is used to write data to the socket instead with a bit more code involved.

什么是那些2种方法之间的区别?利弊?有没有别的东西,应该使用?

What is the difference between those 2 methods? Pros and cons? Is there something else that should be used instead ?

推荐答案

我从来没有使用升压API,所以读者要小心...;)

I've never used the boost API, so reader beware... ;)

在TCP :: iostream的出现,让您用一个类似于流的接口插座进行交互。这种方法与抽象的socket编程的复杂性,所以这将是preferable特别是如果你是新的Socket编程。它使基于TCP的数据共享有很大的意义。这是特别方便,如果你正在做的非常简单的数据交换,如请求/响应。

The tcp::iostream appears to allow you to interact with the socket with a stream-like interface. This approach abstracts the complexities associated with socket programming, so it would be preferable especially if you are new to socket programming. It makes a lot of sense for TCP-based data sharing. It is especially convenient if you are doing very simple data exchanges, such as request/response.

然而,在有些情况下需要通过数据交换低层控制的情况。如果您的接收器在同一时间收到了一堆邮件,你可以preFER读取插座每个消息,而不是从iostream事后处理它们。在发送方,如果您的消息被构造为对象,它往往容易只是发送的对象,而不是首先将对象转换为一个流。读/写功能将是在这种情况下,preferable

However, there are cases where you need lower-level control over the data exchange. If your receiver receives a bunch of messages at the same time, you may prefer to read each message from the socket instead of processing them after the fact from the iostream. On the sender side, if your messages are structured as objects, it is often easier just to send the object instead of first converting the object to a stream. The read/write functionality would be preferable in this case.

从我自己的(非增压)socket编程经验,我通常preFER与较低级别的功能处理,因为它给了我,即使它是稍微复杂一些更大的灵活性。我希望帮助。

From my own (non-boost) socket programming experience, I usually prefer dealing with the lower-level functions since it gives me more flexibility even though it is slightly more complex. I hope that helps.

这篇关于升压,使用TCP,prefered方法通过网络发送的文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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