| | |
| | | |
| | | busSocket = new Socket (AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); |
| | | busSocket.EnableBroadcast = true; |
| | | try { |
| | | try |
| | | { |
| | | 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){ |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log ($"udp port bind error : {ex.Message}"); |
| | | |
| | | busSocket = null; |
| | |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | try |
| | | { |
| | | Packet packet = new Packet (); |
| | | busSocket.BeginReceiveFrom (packet.Bytes, 0, packet.Bytes.Length, SocketFlags.None, ref packet.RemoteEndPoint, new AsyncCallback (asyncEndReceive), packet); |
| | | } |
| | | catch (Exception e) { |
| | | catch (Exception e) |
| | | { |
| | | System.Threading.Thread.Sleep (1); |
| | | Console.WriteLine("asyncBeginReceive " + relinkCount ); |
| | | if (relinkCount == 0) |
| | |
| | | { |
| | | int bytesSent = busSocket.EndSendTo(iar); |
| | | } |
| | | catch { |
| | | catch |
| | | { |
| | | |
| | | } |
| | | } |