Note that there are some explanatory texts on larger screens.

plurals
  1. POSendAsync runs but the data is not really sent
    primarykey
    data
    text
    <p>I have an application that communicate through sockets using the *Async methods (like <a href="http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.sendasync.aspx" rel="nofollow">SendAsync</a>). I'm getting this strange behavior where SendAsync is executed but the data is not sent over the wire.</p> <p>I've enabled network tracing and got the following log:</p> <pre><code>System.Net.Sockets Verbose: 0 : [4300] Socket#5024928::SendAsync() System.Net.Sockets Verbose: 0 : [4300] Socket#5024928::SendAsync(Boolean#1) System.Net.Sockets Verbose: 0 : [7320] Data from Socket#5024928::FinishOperation(SendAsync) System.Net.Sockets Verbose: 0 : [7320] 00000E8C : 01 99 27 00 00 00 01 00-00 00 00 00 00 00 00 00 : ..'............. System.Net.Sockets Verbose: 0 : [7320] 00000E9C : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 : ................ System.Net.Sockets Verbose: 0 : [7320] 00000EAC : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 : ................ System.Net.Sockets Verbose: 0 : [7320] 00000EBC : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 : ................ System.Net.Sockets Verbose: 0 : [7320] 00000ECC : 00 00 B3 F4 : .... System.Net.Sockets Verbose: 0 : [7320] Socket#5024928::ReceiveAsync() System.Net.Sockets Verbose: 0 : [7320] Exiting Socket#5024928::ReceiveAsync() -&gt; Boolean#1 System.Net.Sockets Error: 0 : [7320] Socket#5024928::UpdateStatusAfterSocketError() - TimedOut </code></pre> <p>Although the trace shows that the data was sent (and a receive timeout occurred), the data was not really sent. I've checked with Microsoft's Network Monitor and there's no log of this data being sent.</p> <p>The send method is pretty straightfoward:</p> <pre><code> public void Send(AsyncClientState state, byte[] data) { var socket = state.Socket; var dataTransferredEventArgs = new DataTransferredEventArgs(data, _maxBytes) { State = state }; state.Events.RaiseBeforeSend(dataTransferredEventArgs); byte[] bytesToSend = dataTransferredEventArgs.Bytes.ToArray(); SocketAsyncEventArgs args = GetSocketAsyncEventArgsArgs(socket, bytesToSend.Length); if (args == null) { state.Events.RaiseTimeout(Operation.Send); return; } args.Completed += SendCompleted; args.UserToken = state; Buffer.BlockCopy(bytesToSend, 0, args.Buffer, args.Offset, bytesToSend.Length); bool sendAsync = socket.SendAsync(args); if (!sendAsync) { SendCompleted(this, args); } } private void SendCompleted(object sender, SocketAsyncEventArgs e) { var state = (AsyncClientState) e.UserToken; var events = state.Events; try { if (e.SocketError != SocketError.Success) { events.RaiseError(new ErrorEventArgs("(SendSocketError)" + e.SocketError)); return; } if (e.LastOperation == SocketAsyncOperation.Send) { e.Completed -= SendCompleted; _asyncEventArgsPool.PutBack(e); events.RaiseAfterSend(new StateEventArgs(state)); } } catch (ObjectDisposedException) { } catch (SocketException ex) { events.RaiseError(new ErrorEventArgs(string.Format("{0}: {1}", ex.SocketErrorCode, ex.Message))); } } </code></pre> <p>Am I missing something here? Is the network tracing really reliable?</p> <p><strong>UPDATE</strong></p> <p>I tried to use Begin/End*, but still the same problem. Here is the trace:</p> <pre><code>System.Net.Sockets Verbose: 0 : [6632] Socket#29357909::BeginSend() System.Net.Sockets Verbose: 0 : [6632] Exiting Socket#29357909::BeginSend() -&gt; OverlappedAsyncResult#30136159 System.Net.Sockets Verbose: 0 : [6500] Data from Socket#29357909::PostCompletion System.Net.Sockets Verbose: 0 : [6500] 00000000 : 01 99 27 00 00 00 01 00-00 00 00 00 00 00 00 00 : ..'............. System.Net.Sockets Verbose: 0 : [6500] 00000010 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 : ................ System.Net.Sockets Verbose: 0 : [6500] 00000020 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 : ................ System.Net.Sockets Verbose: 0 : [6500] 00000030 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 : ................ System.Net.Sockets Verbose: 0 : [6500] 00000040 : 00 00 B3 F4 : .... System.Net.Sockets Verbose: 0 : [6500] Socket#29357909::EndSend(OverlappedAsyncResult#30136159) System.Net.Sockets Verbose: 0 : [6500] Exiting Socket#29357909::EndSend() -&gt; Int32#68 System.Net.Sockets Verbose: 0 : [6500] Socket#29357909::BeginReceive() System.Net.Sockets Verbose: 0 : [6500] Exiting Socket#29357909::BeginReceive() -&gt; OverlappedAsyncResult#63504289 System.Net.Sockets Verbose: 0 : [6500] Socket#29357909::EndReceive(OverlappedAsyncResult#63504289) System.Net.Sockets Error: 0 : [6500] Socket#29357909::UpdateStatusAfterSocketError() - TimedOut System.Net.Sockets Error: 0 : [6500] Exception in Socket#29357909::EndReceive - A connection attempt failed because the connected party did not properly respond after a period of time or established connection failed because connected host has failed to respond. System.Net.Sockets Verbose: 0 : [6500] Exiting Socket#29357909::EndReceive() -&gt; Int32#0 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload