| | |
| | | using System; |
| | | using System.Net.Sockets; |
| | | using System.Net; |
| | | using Newtonsoft.Json; |
| | | using System.Text; |
| | | |
| | | namespace HDL_ON.DriverLayer |
| | | { |
| | |
| | | { |
| | | busSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); |
| | | busSocket.EnableBroadcast = true; |
| | | }catch(Exception ex) |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log("Socket 异常 : " + ex.Message); |
| | | } |
| | |
| | | } |
| | | |
| | | asyncBeginReceive(); |
| | | |
| | | MainPage.Log($"udp port : {port}"); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | private int relinkCount = 0; |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 异步接收数据结束 |
| | | /// </summary> |
| | |
| | | packet.Bytes = new byte[len]; |
| | | Array.Copy(bytes, 0, packet.Bytes, 0, packet.Bytes.Length); |
| | | |
| | | //MainPage.Log($"接收{packet.RemoteEndPoint}数据"); |
| | | //mqtt连接数据读取 A协议网络设备信息读取回复 处理 |
| | | if (((IPEndPoint)packet.RemoteEndPoint).Port == 8585) |
| | | { |
| | | Control.Ins.ConvertReceiveData(bytes, ((IPEndPoint)packet.RemoteEndPoint).Address.ToString()); |
| | | var receiveString = Encoding.UTF8.GetString(bytes); |
| | | var res = receiveString.Split("\r\n\r\n"); |
| | | string topic = ""; |
| | | if (res.Length == 2) |
| | | { |
| | | var topics = res[0].Split("\r\n"); |
| | | //MainPage.Log(res[1]); |
| | | foreach (var ts in topics) |
| | | { |
| | | var key = ts.Split(":"); |
| | | switch (key[0]) |
| | | { |
| | | case "Topic": |
| | | topic = key[1]; |
| | | break; |
| | | } |
| | | } |
| | | Control.Ins.ConvertReceiveData(bytes, ((IPEndPoint)packet.RemoteEndPoint).Address.ToString()); |
| | | } |
| | | else if (((IPEndPoint)packet.RemoteEndPoint).Port == 6000)//处理bus 6000端口的数据 |
| | | { |
| | | packet.Manager(); |
| | | } |
| | | } |
| | | else if (((IPEndPoint)packet.RemoteEndPoint).Port == 6000)//处理bus 6000端口的数据 |
| | | { |
| | | packet.Manager(); |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |