protected internal virtual void CreateServer() { var b = new Mono.Ssdp.Client(); //var found = b.Browse(string.Format("upnp:{0}", Name)); var found = b.BrowseAll(); found.Client.ServiceAdded += HandleServiceAdded; found.Start(); _server = new Mono.Ssdp.Server(); _server.Announce(string.Format("upnp:{0}", Name), string.Format("uuid:RemoteMonitor-device:{0}", Name), Address.ToString()); }
public void AnnouncementTest() { using (var server = new Server(CreateRoot())) { using (var client = new Mono.Ssdp.Client()) { var announcements = new Dictionary <string, string> (); announcements.Add("upnp:rootdevice/uuid:d1::upnp:rootdevice", null); announcements.Add("uuid:d1/uuid:d1", null); announcements.Add("urn:schemas-upnp-org:device:mono-upnp-tests-device:1/uuid:d1::urn:schemas-upnp-org:device:mono-upnp-tests-device:1", null); announcements.Add("uuid:ed1/uuid:ed1", null); announcements.Add("urn:schemas-upnp-org:device:mono-upnp-tests-embedded-device:1/uuid:ed1::urn:schemas-upnp-org:device:mono-upnp-tests-embedded-device:1", null); announcements.Add("urn:schemas-upnp-org:service:mono-upnp-test-service:1/uuid:d1::urn:schemas-upnp-org:service:mono-upnp-test-service:1", null); announcements.Add("urn:schemas-upnp-org:service:mono-upnp-test-service:2/uuid:d1::urn:schemas-upnp-org:service:mono-upnp-test-service:2", null); announcements.Add("urn:schemas-upnp-org:service:mono-upnp-test-service:1/uuid:ed1::urn:schemas-upnp-org:service:mono-upnp-test-service:1", null); announcements.Add("urn:schemas-upnp-org:service:mono-upnp-test-service:2/uuid:ed1::urn:schemas-upnp-org:service:mono-upnp-test-service:2", null); client.ServiceAdded += (obj, args) => { lock (mutex) { Assert.AreEqual(ServiceOperation.Added, args.Operation); var announcement = string.Format("{0}/{1}", args.Service.ServiceType, args.Service.Usn); if (announcements.ContainsKey(announcement)) { announcements.Remove(announcement); } if (announcements.Count == 0) { Monitor.Pulse(mutex); } } }; client.BrowseAll(); lock (mutex) { server.Start(); if (!Monitor.Wait(mutex, TimeSpan.FromSeconds(30))) { Assert.Fail("The UPnP server announcement timed out."); } } } } }
public void AnnouncementTest() { using (var server = new Server (CreateRoot ())) { using (var client = new Mono.Ssdp.Client ()) { var announcements = new Dictionary<string,string> (); announcements.Add ("upnp:rootdevice/uuid:d1::upnp:rootdevice", null); announcements.Add ("uuid:d1/uuid:d1", null); announcements.Add ("urn:schemas-upnp-org:device:mono-upnp-tests-device:1/uuid:d1::urn:schemas-upnp-org:device:mono-upnp-tests-device:1", null); announcements.Add ("uuid:ed1/uuid:ed1", null); announcements.Add ("urn:schemas-upnp-org:device:mono-upnp-tests-embedded-device:1/uuid:ed1::urn:schemas-upnp-org:device:mono-upnp-tests-embedded-device:1", null); announcements.Add ("urn:schemas-upnp-org:service:mono-upnp-test-service:1/uuid:d1::urn:schemas-upnp-org:service:mono-upnp-test-service:1", null); announcements.Add ("urn:schemas-upnp-org:service:mono-upnp-test-service:2/uuid:d1::urn:schemas-upnp-org:service:mono-upnp-test-service:2", null); announcements.Add ("urn:schemas-upnp-org:service:mono-upnp-test-service:1/uuid:ed1::urn:schemas-upnp-org:service:mono-upnp-test-service:1", null); announcements.Add ("urn:schemas-upnp-org:service:mono-upnp-test-service:2/uuid:ed1::urn:schemas-upnp-org:service:mono-upnp-test-service:2", null); client.ServiceAdded += (obj, args) => { lock (mutex) { Assert.AreEqual (ServiceOperation.Added, args.Operation); var announcement = string.Format ("{0}/{1}", args.Service.ServiceType, args.Service.Usn); if (announcements.ContainsKey (announcement)) { announcements.Remove (announcement); } if (announcements.Count == 0) { Monitor.Pulse (mutex); } } }; client.BrowseAll (); lock (mutex) { server.Start (); if (!Monitor.Wait (mutex, TimeSpan.FromSeconds (30))) { Assert.Fail ("The UPnP server announcement timed out."); } } } } }
public static int Main(string [] args) { bool show_help = false; for (int i = 0; i < args.Length; i++) { if (args[i][0] != '-') { continue; } switch (args[i]) { case "-t": case "--target": search_targets.Add (args[++i]); break; case "-n": case "--no-strict": Client.StrictProtocol = false; break; case "-h": case "--help": show_help = true; break; case "-v": case "--verbose": verbose = true; break; } } if (show_help) { Console.WriteLine ("Usage: mssdp-client [-t <USN-1> -t <USN-2> ... -t <USN-N>]"); Console.WriteLine (); Console.WriteLine (" -h|--help shows this help"); Console.WriteLine (" -v|--verbose print verbose details of what's happening"); Console.WriteLine (" -t|--target search for specific target"); Console.WriteLine (" -n|--no-strict turn off strict protocol handling"); Console.WriteLine (); Console.WriteLine ("The default search target is ssdp:all to match any UPnP device"); Console.WriteLine (); return 1; } if (!Client.StrictProtocol) { Console.WriteLine ("Strict protocol handling has been disabled. Mono.Ssdp will be more"); Console.WriteLine ("relaxed when parsing SSDP responses and notifications."); Console.WriteLine (); } Console.WriteLine ("Hit ^C when you're bored waiting for responses."); Console.WriteLine (); Client client = new Client (); client.ServiceAdded += OnServiceOperation; client.ServiceRemoved += OnServiceOperation; client.ServiceUpdated += OnServiceOperation; if (search_targets.Count == 0) { search_targets.Add ("ssdp:all"); } if (verbose) { Console.WriteLine ("Searching for the following targets:"); } foreach (string target in search_targets) { if (verbose) { Console.WriteLine (" {0}", target); } client.Browse (target); } if (verbose) { Console.WriteLine (); } while (true) { System.Threading.Thread.Sleep (1000); } }
internal void Dispose (bool removeFromClient) { Stop (); if (removeFromClient) { client.RemoveBrowser (this); } client = null; disposed = true; }
internal Browser (Client client, string serviceType) { this.client = client; this.service_type = serviceType; }
public void Dispose() { Stop (); client.RemoveBrowser (this); client = null; disposed = true; }