void TcpServer_evDataReceived(object sender, SocketServer.DataReceivedEventArgs e) { while (e.Session.dataIn.Count >= 4) { int count = SmppConverter.FromByteArrayToInt32(e.Session.PeekBytes(4)); if (count > _Settings.MaxPduLength) { TcpServer.Disconnect(e.Session.ConnGuid); return; } if (count > e.Session.dataIn.Count) { break; } ProcessPdu(e.Session.ConnGuid, new ByteBuilder(e.Session.dataIn.ToArray(0, count))); e.Session.dataIn.RemoveRange(0, count); } }
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); } } }