File was renamed from HDL_ON/DriverLayer/UdpSocket.cs |
| | |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 监听端口 |
| | | /// </summary> |
| | | public int port |
| | | { |
| | | get |
| | | { |
| | | if ( UserInfo.Current != null && Entity.DB_ResidenceData.residenceData != null) |
| | | { |
| | | return Entity.DB_ResidenceData.residenceData.GatewayType == 0 ? 6000 : 8585; |
| | | } |
| | | return 6000; |
| | | } |
| | | } |
| | | |
| | | //本地Socket |
| | | private Socket busSocket; |
| | | |
| | |
| | | /// </summary> |
| | | public void Start () |
| | | { |
| | | if (IsRunning || port == 0) { |
| | | if (IsRunning ) { |
| | | return; |
| | | } |
| | | |
| | | busSocket = new Socket (AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); |
| | | busSocket.EnableBroadcast = true; |
| | | try { |
| | | busSocket.Bind (new IPEndPoint (IPAddress.Any, port)); |
| | | busSocket.Bind (new IPEndPoint (IPAddress.Any, 6000)); |
| | | |
| | | busSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(IPAddress.Parse("239.0.168.188"))); |
| | | } |
| | |
| | | |
| | | asyncBeginReceive(); |
| | | |
| | | MainPage.Log ($"udp port : {port}"); |
| | | MainPage.Log ($"udp port : 6000"); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | //mqtt连接数据读取 A协议网络设备信息读取回复 处理 |
| | | if (((IPEndPoint)packet.RemoteEndPoint).Port == 8585) |
| | | { |
| | | var reString = System.Text.Encoding.UTF8.GetString(bytes); |
| | | var jt = Newtonsoft.Json.JsonConvert.DeserializeObject<JObject>(reString); |
| | | JToken jtc = null; |
| | | jt.TryGetValue("command", out jtc); |
| | | if (jtc != null && jtc.ToString() == "search_response") |
| | | { |
| | | JToken jto = null; |
| | | jt.TryGetValue("objects", out jto); |
| | | if (jto != null) |
| | | { |
| | | SearchNetDeviceAction?.Invoke(jto.ToString()); |
| | | } |
| | | } |
| | | Common.A_Protocal_Common.apc.ConvertReceiveData(bytes); |
| | | } |
| | | else if(((IPEndPoint)packet.RemoteEndPoint).Port == 6000)//处理bus 6000端口的数据 |
| | | { |