简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM