开发者

Callbacks using asynchronous sockets

My asking is quite simple and is about asynchronous sockets, working with TCP protocol.

When I send some data with the "BeginSend" method, when will the callback be called?

Will it be called when the data is just sent out to the network, or when we are ensured that the data as reached its destination (like it should be regarding to TCP specification) ?

Thanks for your answers.

KiTe.

开发者_C百科

ps : I'm sorry if my english is a bit bad ^^.


From MSDN:

"When your application calls BeginSend, the system will use a separate thread to execute the specified callback method, and will block on EndSend until the Socket sends the number of bytes requested or throws an exception."

"The successful completion of a send does not indicate that the data was successfully delivered. If no buffer space is available within the transport system to hold the data to be transmitted, send will block unless the socket has been placed in nonblocking mode."

http://msdn.microsoft.com/en-us/library/38dxf7kt.aspx


When the callback is called you can be sure that the data has been cleared from the output buffer (the asynchronous operation uses a separate thread to ensure that your calling thread is not blocked in case there is no room in the transmit buffer and it has to wait to send the date) and that it will reach it's destination - but not that it has reached it yet.

Because of the TCP protocol's nature however, you can be sure (well, I guess almost sure) that it will get to the destination, eventually.

However, for timing purposes you should not consider the time of the callback as being the same as the time the data reaches the other party.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜