Exemple #1
0
 public static string RecordRecvData(MessageData data, Action <int> whenLostData)
 {
     if (RecvDatas == null)
     {
         RecvDatas = new Dictionary <string, MessageData>(new avoidException());
     }
     RecvDatas.Add(HexCode.GetString(data.CompleteData), data);
     return(GetCompareResult(whenLostData));
 }
Exemple #2
0
 private static string GetCompareResult(Action <int> /* 丢失差值 */ whenLostData)
 {
     if (SendDatas.Count == RecvDatas.Count)
     {
         if (SendDatas.Last().Key == RecvDatas.Last().Key)
         {
             SendDatas.Remove(SendDatas.Last().Key);
             RecvDatas.Remove(RecvDatas.Last().Key);
             return("正确");
         }
         else
         {
             SendDatas.Remove(SendDatas.Last().Key);
             RecvDatas.Remove(RecvDatas.Last().Key);
             return("错误");
         }
     }
     else
     {
         if (SendDatas.Count < RecvDatas.Count)
         {
             SendDatas = new Dictionary <string, MessageData>(new avoidException());
             RecvDatas = new Dictionary <string, MessageData>(new avoidException());
             return("异常");
         }
         MessageData temp;
         if (SendDatas.Last().Key == RecvDatas.Last().Key)
         {
             whenLostData(SendDatas.Count - RecvDatas.Count);
             SendDatas = new Dictionary <string, MessageData>(new avoidException());
             RecvDatas = new Dictionary <string, MessageData>(new avoidException());
             return("正确");
         }
         if (SendDatas.TryGetValue(RecvDatas.Last().Key, out temp))
         {
             temp = null;
             SendDatas.Remove(RecvDatas.Last().Key);
             RecvDatas.Remove(RecvDatas.Last().Key);
             return("超时");
         }
         temp = null;
         whenLostData(SendDatas.Count - RecvDatas.Count);
         SendDatas = new Dictionary <string, MessageData>(new avoidException());
         RecvDatas = new Dictionary <string, MessageData>(new avoidException());
         return("错误");
     }
 }