void OnGUI() { if (mUDPBox1 == null) { return; } if (mUDPBox2 == null) { return; } if (GUILayout.Button("Start UDPBox1")) { mUDPBox1.Start(); } if (GUILayout.Button("Start UDPBox2")) { mUDPBox2.Start(); } if (GUILayout.Button("udpbox2 -> udpbox1")) { var test = new ACKTestPackage(mUDPBox2.PackageHeadBytes); var bytes = test.Serialize(); mUDPBox2.SendMessage(bytes, new System.Net.IPEndPoint(IPAddress.Parse("127.0.0.1"), 1234)); } }
public override void Process(UDPBox udpBox, byte[] packageBytes, IPEndPoint ipEndPoint) { if (!mTemplate.Deserialize(packageBytes)) { return; } mTemplate.PingPong = mTemplate.PingPong == PingPongPackage.EPingPong.Ping ? PingPongPackage.EPingPong.Pong : PingPongPackage.EPingPong.Ping; udpBox.SendMessage(mTemplate.Serialize(), ipEndPoint); }
bool OnACKMessageIntercept(UDPBox.MessageInterceptInfo messageInterceptInfo) { var result = false; short type = 0; ushort magicNumber = 0; short id = 0; UDPBoxUtility.GetPackageBaseInfo(messageInterceptInfo.Bytes, mUdpBox.PackageHeadBytes, out type, out magicNumber, out id); //-------------------------------------------------------------------- var flag = false; foreach (var item in mPackageInterceptMarkList) { if (item.ID == id && item.MagicNumber == magicNumber) { mPackageInterceptMarkList.Remove(item); flag = true; break; } } if (flag) { return(true); } //--------------------------------------------------------------------Package repeat. if (type == (short)EPackageType.Need_Ack_Session)//Received generic ack package. { mUdpBox.Logger.Log("Recv need ack session package: " + id, EUDPBoxLogType.Log); if (mPackageInterceptMarkList.Count > MAGIC_NUMBER_MARK_COUNT) { mPackageInterceptMarkList.RemoveAt(0); } mPackageInterceptMarkList.Add(new PackageCompareInfo() { ID = id, MagicNumber = magicNumber }); mACKPackageTemplate.ACK_ID = id; mACKPackageTemplate.ACK_MagicNumber = magicNumber; mUdpBox.SendMessage(mACKPackageTemplate.Serialize(), messageInterceptInfo.IPEndPoint); } else if (id == UDPBoxUtility.ACK_ID)//Received ack package. { mUdpBox.Logger.Log("Recv ack package: " + id, EUDPBoxLogType.Log); mACKPackageTemplate.Deserialize(messageInterceptInfo.Bytes); var ack_id = mACKPackageTemplate.ACK_ID; var ack_MagicNumber = mACKPackageTemplate.ACK_MagicNumber; for (int i = mWaitACKInfoList.Count - 1; i >= 0; i--) { var item = mWaitACKInfoList[i]; if (item.MagicNumber == ack_MagicNumber && item.PackageID == ack_id) { mWaitACKInfoList.RemoveAt(i); break; } } result = true; } return(result); }
public void SendUDPMessage(byte[] bytes, IPEndPoint ipEndPoint) { UDPBox.SendMessage(bytes, ipEndPoint); }