internal SSDPWorker(SSDPProperties theProperties) { m_Properties = theProperties; var host = Dns.GetHostEntry(Dns.GetHostName()); foreach (var ip in host.AddressList) { if (ip.AddressFamily == AddressFamily.InterNetwork) { var UdpClient = new UdpClient(); UdpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); UdpClient.Client.Bind(new IPEndPoint(ip, 0)); var ReceiveHandler = new SSDPReceive(UdpClient, ip); ReceiveHandler.DeviceDiscovered += OnDeviceDiscovered; try { UdpClient.AllowNatTraversal(true); } catch (SocketException) { } m_UdpClients.Add(UdpClient); ReceiveHandler.BeginReceive(); } } }
public Response Get(string id) { SSDPProperties SSDPProperties = null; if (!string.IsNullOrEmpty(id)) { SSDPProperties = Core.Instance.SSDPs.FirstOrDefault(SSDP => SSDP.Guid == id); } if (SSDPProperties == null) { var guid = Guid.NewGuid().ToString(); SSDPProperties = new SSDPProperties { Guid = guid, DiscoveryTarget = "", DiscoveryEvent = new Event { Guid = guid, Description = "", Id = guid }, SearchSubscription = new Subscription { Guid = Guid.NewGuid().ToString(), Id = "" } }; } return(new Response { Model = SSDPProperties, Template = "NetworkSSDPView" }); }
public void UpdateProperties(SSDPProperties theProperties) { bool EventUpdatedFlag = false; bool SubscriptionUpdatedFlag = false; if (theProperties.DiscoveryEvent.Id != DiscoveryEvent.Id) { DiscoveryEvent.Id = theProperties.DiscoveryEvent.Id; EventUpdatedFlag = true; } if (theProperties.DiscoveryEvent.Description != DiscoveryEvent.Description) { DiscoveryEvent.Description = theProperties.DiscoveryEvent.Description; EventUpdatedFlag = true; } if (theProperties.DiscoveryTarget != DiscoveryTarget) { DiscoveryTarget = theProperties.DiscoveryTarget; } if (theProperties.SearchSubscription != null && theProperties.SearchSubscription.Id != SearchSubscription.Id) { SearchSubscription.Id = theProperties.SearchSubscription.Id; SubscriptionUpdatedFlag = true; } /// /// ... /// if (EventUpdatedFlag) { EventsUpdated?.Invoke(); } if (SubscriptionUpdatedFlag) { SubscriptionsUpdated?.Invoke(); } }