| | |
| | | /// 所有对一端口的控制都会放到这个集合里 |
| | | /// </summary> |
| | | static List<Control_Udp> controlList = new List<Control_Udp>(50); |
| | | |
| | | |
| | | public System.Net.IPEndPoint EndPoint |
| | | { |
| | |
| | | /// <summary> |
| | | /// 重发验证 |
| | | /// </summary> |
| | | public void ReceiveRepeatManager(string receiveFlag) |
| | | public static void ReceiveRepeatManager(string receiveFlag,byte []usefulBytes) |
| | | { |
| | | for (int i = 0; i < controlList.Count; i++) |
| | | { |
| | |
| | | { |
| | | for (int i = 0; i < controlList.Count;) |
| | | { |
| | | if (controlList[i] == null || 3 <= controlList[i].Packet.HaveSendCount) |
| | | if (controlList[i] == null || 3 <= controlList[i].packet.HaveSendCount) |
| | | { |
| | | controlList.RemoveAt(i); |
| | | } |
| | |
| | | void run() |
| | | { |
| | | allDone.Set(); |
| | | Packet.HaveSendCount = 4; |
| | | packet.HaveSendCount = 4; |
| | | } |
| | | |
| | | //数据发送处理 |
| | |
| | | new System.Threading.Thread(() => |
| | | { |
| | | System.Threading.Thread.Sleep(1000); |
| | | UdpSocket._BusSocket.Start(6000); |
| | | UdpSocket._BusSocket.Start(UdpSocket._BusSocket.Port); |
| | | controlLostCount = 0; |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | |
| | | |
| | | try |
| | | { |
| | | MainPage.Log("发送数据:" + SendFlag); |
| | | UdpSocket._BusSocket.AsyncBeginSend(Packet); |
| | | Packet.HaveSendCount--; |
| | | //MainPage.Log("发送数据:" + SendFlag); |
| | | UdpSocket._BusSocket.AsyncBeginSend(packet); |
| | | packet.HaveSendCount--; |
| | | |
| | | //这里是重发两次 |
| | | while (Packet.HaveSendCount < 3) |
| | | while (packet.HaveSendCount < 3) |
| | | { |
| | | if (Packet.FlagDateTime.AddMilliseconds(1000).Ticks <= DateTime.Now.Ticks) |
| | | if (packet.FlagDateTime.AddMilliseconds(1000).Ticks <= DateTime.Now.Ticks) |
| | | { |
| | | MainPage.Log("重发数据:" + SendFlag); |
| | | UdpSocket._BusSocket.AsyncBeginSend(Packet); |
| | | UdpSocket._BusSocket.AsyncBeginSend(packet); |
| | | controlLostCount++; |
| | | } |
| | | System.Threading.Thread.Sleep(100); |
| | |
| | | /// <summary> |
| | | /// 当前数据包 |
| | | /// </summary> |
| | | Packet Packet; |
| | | Packet packet; |
| | | /// <summary> |
| | | /// 记录发送数据包 |
| | | /// </summary> |
| | |
| | | { |
| | | try |
| | | { |
| | | Packet = new Packet(target.SendBytes, target.IPEndPoint); |
| | | Packet.HaveSendCount = 3 - sendCount; |
| | | packet = new Packet(target.SendBytes, target.IPEndPoint); |
| | | packet.HaveSendCount = 3 - sendCount; |
| | | |
| | | signPacket(target); |
| | | |
| | | System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(managerSendCount)); |
| | | thread.IsBackground = true; |
| | | thread.Start(Packet); |
| | | thread.Start(packet); |
| | | |
| | | if (isWait) |
| | | { |
| | |
| | | |
| | | var sendBytes = Control.Ins.ConvertSendBodyData(CommunicationTopic.SearchLoaclGateway, bodyString); |
| | | //组播发送 |
| | | Packet = new Packet(sendBytes, new System.Net.IPEndPoint(System.Net.IPAddress.Parse("239.0.168.188"), 8585)); |
| | | Packet.HaveSendCount = 4;//ps:没有重发,后期有时间可以增加重发判断 |
| | | packet = new Packet(sendBytes, new System.Net.IPEndPoint(System.Net.IPAddress.Parse("239.0.168.188"), 8585)); |
| | | packet.HaveSendCount = 4;//ps:没有重发,后期有时间可以增加重发判断 |
| | | System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(managerSendCount)); |
| | | thread.IsBackground = true; |
| | | thread.Start(Packet); |
| | | thread.Start(packet); |
| | | //wait();不需要等待 |
| | | } |
| | | catch (Exception ex) |
| | |
| | | MainPage.Log($"Send bus data error {ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 发送udp A协议数据 |
| | | /// </summary> |
| | | public void SendLocalHdlLinkData(byte[] sendBytes) |
| | | public void SendLocalHdlLinkData(byte[] sendBytes,string id, bool isWait=false) |
| | | { |
| | | if (controlLostCount > 3) |
| | | { |
| | | UdpSocket._BusSocket.Stop(); |
| | | UdpSocket._BusSocket.Start(8585); |
| | | controlLostCount = 0; |
| | | } |
| | | Packet = new Packet(sendBytes, new System.Net.IPEndPoint(System.Net.IPAddress.Parse(Control.Ins.reportIp), 8585)); |
| | | Packet.HaveSendCount = 2;//ps:没有重发,后期有时间可以增加重发判断 |
| | | |
| | | packet = new Packet(sendBytes, new System.Net.IPEndPoint(System.Net.IPAddress.Parse(Control.Ins.reportIp), 8585)); |
| | | sendFlag = id; |
| | | System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(managerSendCount)); |
| | | thread.IsBackground = true; |
| | | thread.Start(Packet); |
| | | controlLostCount++; |
| | | thread.Start(packet); |
| | | if (isWait) |
| | | { |
| | | wait(); |
| | | } |
| | | //MainPage.Log($"发送Hdl-Link数据,IP:{Control.Ins.reportIp}:8585"); |
| | | } |
| | | } |
| | | |
| | | } |