views:

293

answers:

1

Hi guys,

Here is a scenario with asynchronous sockets that I dont't quite understand... I have 2 Tcp sockets, a client socket & a server socket. My server socket is bound & listening on a port.

My client sockets connect to the server socket (using BeginConnect / EndConnect). I then send a message to the server using BeginSend(). On the server side, I don't do a Receive() or BeginReceive().

What happens is that my AsyncCallback specified for my BeginSend call gets invoked & its IAsyncResult tells me that it completed & the call to Socket.EndSend() does not raise any exception...

Is there something that I don't get or shouldn't my AsyncCallback be called only if the BeginSend call actually sends something to the server (ie.: callback called after the server has received all bytes)? If there was no receive done on the server, shouldn't my callback be called after the sendtimeout expires and my call to Socket.EndSend then would raise an exception?

Thanks

+1  A: 

Nope, TCP/IP handles all this for you. There's buffers at both sides of the connection that will hold the data until it can be received. Without the buffering, there would probably be horrible latency when sending chatty communication.

Think of it like mailing a letter. It sits in your mailbox until the mail man picks it up. Once that happens, it's been sent. It hasn't yet been received. It could be in transit, or it could be waiting in their mailbox for them to read.

So getting the callback after BeginSend only tells you that it was sent. The only way to know for sure that the other side received and processed the data is to request some time of acknowledgement back.

Josh Einstein