发现如果通过TCP消息交付 [英] Finding out if a message over tcp was delivered

查看:104
本文介绍了发现如果通过TCP消息交付的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我发送()/写()通过TCP流的消息,我怎么能找到,如果这些字节被成功交付?

When i send()/write() a message over a tcp stream, how can i find out if those bytes were successfully delivered?

接收器接收确认通过TCP字节,所以发件人TCP协议栈应该知道的。

The receiver acknowledges receiving the bytes via tcp, so the senders tcp stack should know.

但是,当我向()一些字节,发送()立即返回,即使该数据包不能(还)交付,我测试了使用上的netcat strace的2.6.30的Linux,在发送前拉我的网线出一些字节。

But when I send() some bytes, send() immediately returns, even if the packet could not (yet) be delivered, i tested that on linux 2.6.30 using strace on netcat, pulling my network cable out before sending some bytes.

我只是开发一个应用程序它是非常重要的知道,如果生了一个消息,但实现TCP功能(ACK消息#123)觉得别扭,必须有一个更好的办法。

I am just developing an application where it is very important to know if a message was delivered, but implementing tcp features ("ack for message #123") feels awkward, there must be a better way.

推荐答案

发送TCP不知道什么时候得到的数据被另一端确认,但唯一的原因,它会是这样,它知道什么时候可以丢弃数据(因为别人现在负责这让应用程序在另一侧)。

The sending TCP does know when the data gets acknowledged by the other end, but the only reason it does this is so that it knows when it can discard the data (because someone else is now responsible for getting it to the application at the other side).

这通常不提供这些信息发送应用程序,因为(尽管出场),它不会真正的的意思是的太多发送应用程序。确认并不意味着接收应用程序已经得到的数据,并做了一些理智的对待它 - 它的意思是,发送TCP不再需要担心。数据仍可能在运输过程中 - 中间代理服务器中,例如,或者在接收TCP堆栈内

It doesn't typically provide this information to the sending application, because (despite appearances) it wouldn't actually mean much to the sending application. The acknowledgement doesn't mean that the receiving application has got the data and done something sensible with it - all it means is that the sending TCP no longer has to worry about it. The data could still be in transit - within an intermediate proxy server, for example, or within the receiving TCP stack.

数据成功收到确实是一个应用程序级的概念 - 这意味着什么取决于应用程序(例如,对于很多应用来说只会是有意义的考虑数据收到一旦被同步到磁盘的不同而不同在接收侧)。因此,这意味着你必须自己实现它,因为作为应用程序开发人员,你真的是唯一一个有能力知道该怎么做理智您的应用程序。

"Data successfully recieved" is really an application-level concept - what it means varies depending on the application (for example, for many applications it would only make sense to consider the data "recieved" once it has been synced to disk on the receiving side). So that means you have to implement it yourself, because as the application developer, you're really the only one in a position to know how to do it sensibly for your application.

这篇关于发现如果通过TCP消息交付的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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