/// <summary> /// 接收底层的数据 /// </summary> /// <param name="sender"></param> /// <param name="token"></param> private void UDPSocket_OnDataReceived(object sender, AsyncUdpUserToken token) { Console.WriteLine("接收数据个数:" + token.Length); switch (token.Data[token.Offset]) { case 0: { //数据 socketEndPoint.Add(token); if (isValidatePoint) { isValidatePoint = false; EndPointValidate(); } } break; case 1: { //接收完成序列 Console.WriteLine("接收小包完成返回"); SendQueue sendQueue = null; LosPackage rsp = new LosPackage(token.Data); if (dicSendQueue.TryGetValue(rsp.packageID, out sendQueue)) { sendQueue.Add(rsp.packageSeq); } } break; case 2: { //丢失序列 Console.WriteLine("接收丢失请求"); SendQueue sendQueue = null; LosPackage rsp = new LosPackage(token.Data); if (dicSendQueue.TryGetValue(rsp.packageID, out sendQueue)) { AsyncUdpUserToken resend = sendQueue.GetAsyncUdpUserToken(rsp.packageSeq); if (resend != null) { uDPPack.Send(resend, 0); } } } break; case 3: { //完成接收 SendQueue sendQueue = null; LosPackage rsp = new LosPackage(token.Data); if (dicSendQueue.TryRemove(rsp.packageID, out sendQueue)) { sendQueue.Clear(); } Console.WriteLine("接收完成返回:" + rsp.packageID); } break; } }