public override void OnReceiveData(ChoConnectionState state) { while (state.AvailableData > 0) { int readBytes = state.Read(state.Buffer, 0, state.Buffer.Length); byte[] buffer = state.Buffer.Take(readBytes).ToArray(); if (_inbuffer == null) { _inbuffer = buffer; _headerFound = false; } else { _inbuffer = ChoByteArrayEx.Combine(_inbuffer, buffer); } try { if (!_headerFound) { _msgBodySize = ProcessHeader(out _headerFound); } if (_headerFound) { ProcessBody(state, _msgBodySize); } } catch (Exception ex) { ChoTrace.Write(ex); } } }
public override void OnReceiveData(ChoConnectionState state) { while (state.AvailableData > 0) { int readBytes = state.Read(state._buffer, 0, state._buffer.Length); byte[] buffer = state._buffer.Take(readBytes).ToArray(); if (_inbuffer == null) { _inbuffer = buffer; } else { _inbuffer = ChoByteArrayEx.Combine(_inbuffer, buffer); } if (!_headerFound) { _msgBodySize = ProcessHeader(); if (_headerFound) { ProcessBody(); } } else { ProcessBody(); } } }
public override void OnReceiveData(ChoConnectionState state) { byte[] buffer = new byte[1024]; while (state.AvailableData > 0) { int readBytes = state.Read(buffer, 0, 1024); if (readBytes > 0) { _receivedStr += Encoding.UTF8.GetString(buffer, 0, readBytes); if (_receivedStr.IndexOf("<EOF>") >= 0) { state.Write(Encoding.UTF8.GetBytes(_receivedStr), 0, _receivedStr.Length); _receivedStr = ""; } } else { state.EndConnection(); } //If read fails then close connection } }