| | |
| | | { |
| | | if (IsRunning) |
| | | { |
| | | if (port == Port) |
| | | if (port == Port) |
| | | { |
| | | return; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | busSocket.Close(); |
| | | } |
| | | } |
| | | } |
| | | if (port != 0) |
| | | Port = port; |
| | |
| | | busSocket.Bind(new IPEndPoint(IPAddress.Any, Port)); |
| | | |
| | | busSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(IPAddress.Parse("239.0.168.188"))); |
| | | relinkCount = 0; |
| | | } |
| | | catch (Exception ex){ |
| | | MainPage.Log ($"udp port bind error : {ex.Message}"); |
| | |
| | | /// </summary> |
| | | public void Stop() |
| | | { |
| | | if(busSocket == null) |
| | | { |
| | | return; |
| | | } |
| | | if (!IsRunning) |
| | | { |
| | | return; |
| | |
| | | try |
| | | { |
| | | busSocket.Close(); |
| | | relinkCount = 0; |
| | | } |
| | | catch { } |
| | | busSocket = null; |
| | | MainPage.Log("Socket关闭"); |
| | | MainPage.Log("Socket关闭"); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | return; |
| | | } |
| | | if(busSocket == null) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | Packet packet = new Packet (); |
| | |
| | | } |
| | | catch (Exception e) { |
| | | System.Threading.Thread.Sleep (1); |
| | | asyncBeginReceive (); |
| | | Console.WriteLine("asyncBeginReceive " + relinkCount ); |
| | | if (relinkCount == 0) |
| | | { |
| | | relinkCount = 1; |
| | | asyncBeginReceive(); |
| | | } |
| | | Console.WriteLine($"asyncBeginReceive {e.Message}"); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 重连次数 |
| | | /// </summary> |
| | | private int relinkCount = 0; |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 异步接收数据结束 |
| | |
| | | //mqtt连接数据读取 A协议网络设备信息读取回复 处理 |
| | | if (((IPEndPoint)packet.RemoteEndPoint).Port == 8585) |
| | | { |
| | | MainPage.Log($"局域网udp信息"); |
| | | Control.Ins.ConvertReceiveData(bytes, ((IPEndPoint)packet.RemoteEndPoint).Address.ToString()); |
| | | } |
| | | else if (((IPEndPoint)packet.RemoteEndPoint).Port == 6000)//处理bus 6000端口的数据 |