void TcpConnection_DataReceived(object sender, SockClient.DataReceivedEventArgs e) { LastReceptionTime = DateTime.Now; while (TcpConnection.ReadSize() >= 0x10) { int bytes = SmppConverter.FromByteArrayToInt32(TcpConnection.PeekBytes(4)); if (bytes > Settings.MaxPduSize) { TcpConnection.Disconnect(); return; } if (bytes > TcpConnection.ReadSize()) { break; } var bb = new ByteBuilder(TcpConnection.ReadByteArray(bytes, 0)); var header = new SmppHeader(bb); SmppAsyncObject asyncObject = FindAsyncObject(header.SequenceNumber); if (asyncObject != null) { asyncObject.PduRes = bb; if (asyncObject.mre != null) { asyncObject.mre.Set(); } else if (asyncObject.Callback != null) { new SmppCompletionCallbackHandler(ProcessAsyncPdu).BeginInvoke(asyncObject, SmppAsyncObject.SmppAsyncCompleted.Response, null, null); } } else { ProcessPdu(bb); } } }