protected void SendCompleted(IAsyncResult result) { RCAsyncState state = (RCAsyncState)result.AsyncState; try { // Don't know what to do with the count returned... Anything? _socket.EndSend(result); // Dequeue the next item for sending on this channel. // if (next != null) RCAsyncState next = _outbox.Remove(); if (next != null) { TcpSendState correlation = (TcpSendState)next.Other; byte[] payload = Encoding.ASCII.GetBytes(correlation.Message.ToString()); int size = _buffer.PrepareSend(correlation.Id, payload); _socket.BeginSend(_buffer.SendBuffer, 0, size, SocketFlags.None, new AsyncCallback(SendCompleted), state); // Console.Out.WriteLine ("Server sending {0}", correlation.Id); // Send (next.Runner, next.Closure, other.Id, other.Message); } } catch (Exception ex) { state.Runner.Report(state.Closure, ex); } }
protected void SendCompleted(IAsyncResult result) { RCAsyncState state = (RCAsyncState)result.AsyncState; try { // Don't know what to do with the count returned... Anything? _socket.EndSend(result); // Dequeue the next item for sending on this channel. RCAsyncState next = _outbox.Remove(); if (next != null) { // Send will add the header to the payload. // This is something I will probably want to change by adding some kind of // serializer/formatter abstraction. TcpSendState correlation = (TcpSendState)next.Other; byte[] payload = _protocol.Serialize(this, correlation.Message); int size = _buffer.PrepareSend(correlation.Id, payload); _socket.BeginSend(_buffer.SendBuffer, 0, size, SocketFlags.None, new AsyncCallback(SendCompleted), state); // Console.Out.WriteLine ("Client sending {0}", correlation.Id); } } catch (Exception ex) { state.Runner.Report(state.Closure, ex); } }