/// <summary> /// Removes the announcer. /// </summary> /// <param name="announcer">The announcer.</param> public void RemoveAnnouncer(ISsdpAnnouncer announcer) { lock (this.Announcers) { this.Announcers.Remove(announcer); } }
/// <summary> /// Sends the search response message. /// </summary> protected void SendSearchResponse(SsdpMessage msg, ISsdpAnnouncer announcer) { // If we were stopped then don't bother sending this message if (!this.Server.IsListening) { return; } // Determine matching locations to respond with // If none are found then just respond with all of our locations var locations = announcer.GetLocations(addr => addr.Equals(msg.Destination.Address)).ToArray(); if (!locations.Any()) { locations = announcer.GetLocations(addr => addr.AddressFamily == msg.Source.AddressFamily).ToArray(); } foreach (var location in locations) { var response = Protocol.CreateSearchResponse(location, msg.SearchType, announcer.USN, announcer.MaxAge, Protocol.DefaultUserAgent); byte[] bytes = Encoding.ASCII.GetBytes(response); Trace.WriteLine(string.Format("Sending SearchResponse [{0}, {1}] from {2} to {3}", msg.SearchType, msg.USN, this.Server.LocalEndpoint, msg.Source), AppInfo.Application); this.Server.Send(bytes, bytes.Length, msg.Source); } }
/// <summary> /// Sets the search responses. /// </summary> /// <param name="announcer">The announcer.</param> /// <param name="respondToSearches">if set to <c>true</c> [respond to searches].</param> public void SetRespondsToSearches(ISsdpAnnouncer announcer, bool respondToSearches) { lock (this.Announcers) { if (!this.Announcers.ContainsKey(announcer)) { throw new KeyNotFoundException(); } this.Announcers[announcer] = respondToSearches; } }
/// <summary> /// Sends the search response message. /// </summary> protected void SendSearchResponse(SsdpMessage msg, ISsdpAnnouncer announcer) { this.Sockets.ForEachSocket(socket => { // If we were stopped then don't bother sending this message if (!socket.IsListening) { return; } var aliveResponse = Protocol.CreateAliveResponse(socket.Location.ToString(), msg.SearchType, announcer.USN, announcer.MaxAge, Protocol.DefaultUserAgent); var bytes = Encoding.ASCII.GetBytes(aliveResponse); Trace.WriteLine(string.Format("Sending SearchResponse [{0}, {1}] from {2} to {3}", msg.SearchType, msg.USN, socket.LocalEndpoint, msg.Source), AppInfo.Application); socket.Send(bytes, bytes.Length, msg.Source); }); }
private void SetupOnRemovedHandler(UpnpDevice device, ISsdpAnnouncer ad1, ISsdpAnnouncer ad2) { EventHandler <EventArgs <UpnpDevice> > onRemoved = null; onRemoved = (sender, args) => { ad1.Shutdown(); ad2.Shutdown(); this.SsdpServer.RemoveAnnouncer(ad1); this.SsdpServer.RemoveAnnouncer(ad2); device.Removed -= onRemoved; }; device.Removed += onRemoved; }
/// <summary> /// Sends the search response message. /// </summary> protected void SendSearchResponse(SsdpMessage msg, ISsdpAnnouncer announcer) { this.Sockets.ForEachSocket(socket => { // If we were stopped then don't bother sending this message if (!socket.IsListening) return; var aliveResponse = Protocol.CreateAliveResponse(socket.Location.ToString(), msg.SearchType, announcer.USN, announcer.MaxAge, Protocol.DefaultUserAgent); var bytes = Encoding.ASCII.GetBytes(aliveResponse); Trace.WriteLine(string.Format("Sending SearchResponse [{0}, {1}] from {2} to {3}", msg.SearchType, msg.USN, socket.LocalEndpoint, msg.Source), AppInfo.Application); socket.Send(bytes, bytes.Length, msg.Source); }); }
/// <summary> /// Sets the search responses. /// </summary> /// <param name="announcer">The announcer.</param> /// <param name="respondToSearches">if set to <c>true</c> [respond to searches].</param> public void SetRespondsToSearches(ISsdpAnnouncer announcer, bool respondToSearches) { lock (this.Announcers) { if (!this.Announcers.ContainsKey(announcer)) throw new KeyNotFoundException(); this.Announcers[announcer] = respondToSearches; } }
/// <summary> /// Removes the announcer. /// </summary> /// <param name="announcer">The announcer.</param> public void RemoveAnnouncer(ISsdpAnnouncer announcer) { lock (this.Announcers) { this.Announcers.Remove(announcer); } }
private void SetupOnRemovedHandler(UpnpDevice device, ISsdpAnnouncer ad1, ISsdpAnnouncer ad2) { EventHandler<EventArgs<UpnpDevice>> onRemoved = null; onRemoved = (sender, args) => { ad1.Shutdown(); ad2.Shutdown(); this.SsdpServer.RemoveAnnouncer(ad1); this.SsdpServer.RemoveAnnouncer(ad2); device.Removed -= onRemoved; }; device.Removed += onRemoved; }