private static SerializedInfo ParseForKeepAlive(byte[] packet) { byte sessionLength = packet[PacketConstants.SessionLengthIndex]; string sessionStr = PacketConstants.SessionEncoding.GetString(packet, PacketConstants.HeadLength, sessionLength); Session session = SessionMapping.Get(sessionStr); return(SerializedInfo.CreateForKeepAlive(session, true, packet)); }
private void OnServerConnectionAvailable(object sender, SecureConnectionResults args) { try { if (args.AsyncException != null) { _Log.ErrorFormat("Client connection failed {0}", args.AsyncException); return; } SslInfo sslInfo = args.SecureInfo; Session session = SessionMapping.Get(); Client client = new Client(sslInfo.SslStream, session, sslInfo.NetworkStream.BufferInUsed, sslInfo.Socket); SenderReceiverPair relation = new SenderReceiverPair(client, new ReceiveAgent()); Application.Default.AgentController.Add(session, relation.Receiver, relation.Sender); } catch (Exception ex) { _Log.Error(ex); } }
private static SerializedInfo ParseForGeneral(byte[] packet) { byte sessionLength = packet[PacketConstants.SessionLengthIndex]; byte[] contentLengthBytes = new byte[PacketConstants.ContentHeaderLength]; Array.Copy(packet, PacketConstants.ContentLengthIndex, contentLengthBytes, 0, PacketConstants.ContentHeaderLength); int contentLength = contentLengthBytes.ToCustomerInt(); byte[] contentBytes = new byte[contentLength]; int contentIndex = PacketConstants.HeadLength + sessionLength; Array.Copy(packet, contentIndex, contentBytes, 0, contentLength); string sessionStr = PacketConstants.SessionEncoding.GetString(packet, PacketConstants.HeadLength, sessionLength); Session session = SessionMapping.Get(sessionStr); string content = PacketConstants.ContentEncoding.GetString(contentBytes); bool isContentInJsonFormat = (packet[PacketConstants.SettingIndex] & PacketFirstHeadByteValue.IsJsonFormatMask) == PacketFirstHeadByteValue.IsJsonFormatMask; if (isContentInJsonFormat) { return(ParseJsonPacket(session, content)); } return(ParseXmlPacket(session, content)); }