4 This file is part of avahi.
6 avahi is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 avahi is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
14 Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with avahi; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 using System.Collections;
28 public class AvahiTest {
29 private static Client client;
30 private static ArrayList objects = new ArrayList ();
32 public static void Main () {
33 client = new Client ();
35 EntryGroup eg = new EntryGroup (client);
36 eg.StateChanged += OnEntryGroupChanged;
37 eg.AddService ("foobar2", "_daap._tcp", client.DomainName,
38 444, new string[] { "foo", "bar", "baz" });
40 Console.WriteLine ("Press enter to quit");
44 private static void OnEntryGroupChanged (object o, EntryGroupStateArgs args)
46 Console.WriteLine ("Entry group status: " + args.State);
47 if (args.State == EntryGroupState.Established) {
48 DomainBrowser browser = new DomainBrowser (client);
49 objects.Add (browser);
51 browser.DomainAdded += OnDomainAdded;
55 private static void OnDomainAdded (object o, DomainInfoArgs args)
57 Console.WriteLine ("Got domain added: " + args.Domain.Domain);
58 BrowseServiceTypes (args.Domain.Domain);
61 private static void BrowseServiceTypes (string domain)
63 ServiceTypeBrowser stb = new ServiceTypeBrowser (client, domain);
66 stb.CacheExhausted += OnCacheExhausted;
67 stb.ServiceTypeAdded += OnServiceTypeAdded;
70 private static void OnCacheExhausted (object o, EventArgs args)
72 Console.WriteLine ("Cache is exhausted");
75 private static void OnServiceTypeAdded (object o, ServiceTypeInfoArgs args)
77 Console.WriteLine ("Got service type: " + args.ServiceType.ServiceType);
78 ServiceBrowser sb = new ServiceBrowser (client, args.ServiceType.ServiceType, args.ServiceType.Domain);
81 sb.ServiceAdded += OnServiceAdded;
84 private static void OnServiceAdded (object o, ServiceInfoArgs args)
86 // Console.WriteLine ("Got service: " + info.Name);
87 ServiceResolver resolver = new ServiceResolver (client, args.Service);
88 objects.Add (resolver);
89 resolver.Found += OnServiceResolved;
92 private static void OnServiceResolved (object o, ServiceInfoArgs args)
96 Console.WriteLine ("Service '{0}' at {1}:{2}", args.Service.Name, args.Service.HostName, args.Service.Port);
97 foreach (byte[] bytes in args.Service.Text) {
98 Console.WriteLine ("Text: " + Encoding.UTF8.GetString (bytes));
100 AddressResolver ar = new AddressResolver (client, args.Service.Address);
103 ar.Found += OnAddressResolved;
106 private static void OnAddressResolved (object o, HostAddressArgs args)
110 Console.WriteLine ("Resolved {0} to {1}", args.Address, args.Host);
111 HostNameResolver hr = new HostNameResolver (client, args.Host);
114 hr.Found += OnHostNameResolved;
117 private static void OnHostNameResolved (object o, HostAddressArgs args)
120 Console.WriteLine ("Resolved {0} to {1}", args.Host, args.Address);