开发者

Ensuring send() data delivered

开发者 https://www.devze.com 2023-02-07 10:40 出处:网络
Is there any way of checking if data sent using winsock\'s send() or WSASend() are really delivered to destination?

Is there any way of checking if data sent using winsock's send() or WSASend() are really delivered to destination?

I'm writing an application talking with third party server, which sometimes goes down after working for some time, and need to be sure if messages sent to that 开发者_高级运维server are delivered or not. The problem is sometimes calling send() finishes without error, even if server is already down, and only next send() finishes with error - so I have no idea if previous message was delivered or not.

I suppose on TCP layer there is information if certain (or all) packets sent were acked or not, but it is not available using socket interface (or I cannot find a way).

Worst of all, I cannot change the code of the server, so I can't get any delivery confirmation messages.


I'm sorry, but given what you're trying to achieve, you should realise that even if the TCP stack COULD give you an indication that a particular set of bytes has been ACK'd by the remote TCP stack it wouldn't actually mean anything different to what you know at the moment.

The problem is that unless you have an application level ACK from the remote application which is only sent once the remote application has actioned the data that you have sent to it then you will never know for sure if the data has been received by the remote application.

'but I can assume its close enough'

is just delusional. You may as well make that assumption if your send completes as it's about as valid.

The issue is that even if the TCP stack could tell you that the remote stack had ACK'd the data (1) that's not the same thing as the remote application receiving the data (2) and that is not the same thing as the remote application actually USING the data (3).

Given that the remote application COULD crash at any point, 1, 2 OR 3 the only worthwhile indication that the data has arrived is one that is sent by the remote application after it has used the data for the intended purpose.

Everything else is just wishful thinking.


Not from the return to send(). All send() says is that the data was pushed into the send buffer. Connected socket streams are not guarenteed to send all the data, just that the data will be in order. So you can't assume that your send() will be done in a single packet or if it will ever occur due to network delay or interruption.

If you need a full acknowledgement, you'll have to look at higher application level acks (server sending back a formatted ack message, not just packet ACKs).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号