views:

146

answers:

2

Hello.

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 ^^.

+3  A: 

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

Note this is different than BeginReceive/EndReceive.
Jess
+2  A: 

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.

Miky Dinescu
ok thanks to both of you, that is exactly what I was searching for.
KiTe
you're welcome..
Miky Dinescu