2 This file is part of avahi.
4 avahi is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
9 avahi is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
12 Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with avahi; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 using System.Collections;
26 public class AvahiTest {
27 private static Client client;
28 private static ArrayList objects = new ArrayList ();
30 public static void Main () {
31 client = new Client ();
33 Console.WriteLine ("joined service name: " + Client.JoinServiceName ("FooBar", "_foo", "local"));
35 EntryGroup eg = new EntryGroup (client);
36 eg.StateChanged += OnEntryGroupChanged;
37 eg.AddService ("foobar2", "_dingdong._tcp", client.DomainName,
38 444, new string[] { "foo=stuff", "bar=stuff2", "baz=stuff3" });
40 BrowseServiceTypes ("local");
41 Console.WriteLine ("Press enter to quit");
46 private static void OnEntryGroupChanged (object o, EntryGroupStateArgs args)
48 Console.WriteLine ("Entry group status: " + args.State);
49 if (args.State == EntryGroupState.Established) {
50 DomainBrowser browser = new DomainBrowser (client);
51 objects.Add (browser);
53 browser.DomainAdded += OnDomainAdded;
57 private static void OnDomainAdded (object o, DomainInfoArgs args)
59 Console.WriteLine ("Got domain added: " + args.Domain.Domain);
60 // BrowseServiceTypes (args.Domain.Domain);
63 private static void BrowseServiceTypes (string domain)
65 ServiceTypeBrowser stb = new ServiceTypeBrowser (client, domain);
68 stb.CacheExhausted += OnCacheExhausted;
69 stb.ServiceTypeAdded += OnServiceTypeAdded;
72 private static void OnCacheExhausted (object o, EventArgs args)
74 Console.WriteLine ("Cache is exhausted");
77 private static void OnServiceTypeAdded (object o, ServiceTypeInfoArgs args)
79 Console.WriteLine ("Got service type: " + args.ServiceType.ServiceType);
80 ServiceBrowser sb = new ServiceBrowser (client, args.ServiceType.ServiceType, args.ServiceType.Domain);
83 sb.ServiceAdded += OnServiceAdded;
86 private static void OnServiceAdded (object o, ServiceInfoArgs args)
88 // Console.WriteLine ("Got service: " + info.Name);
89 ServiceResolver resolver = new ServiceResolver (client, args.Service);
90 objects.Add (resolver);
91 resolver.Found += OnServiceResolved;
94 private static void OnServiceResolved (object o, ServiceInfoArgs args)
98 Console.WriteLine ("Service '{0}' at {1}:{2}", args.Service.Name, args.Service.HostName, args.Service.Port);
99 foreach (byte[] bytes in args.Service.Text) {
100 Console.WriteLine ("Text: " + Encoding.UTF8.GetString (bytes));
103 AddressResolver ar = new AddressResolver (client, args.Service.Address);
106 ar.Found += OnAddressResolved;
107 ar.Failed += OnAddressResolverFailed;
110 private static void OnAddressResolverFailed (object o, ErrorCodeArgs args)
112 Console.WriteLine ("Failed to resolve '{0}': {1}", (o as AddressResolver).Address, args.ErrorCode);
115 private static void OnAddressResolved (object o, HostAddressArgs args)
119 Console.WriteLine ("Resolved {0} to {1}", args.Address, args.Host);
120 HostNameResolver hr = new HostNameResolver (client, args.Host);
123 hr.Found += OnHostNameResolved;
126 private static void OnHostNameResolved (object o, HostAddressArgs args)
129 Console.WriteLine ("Resolved {0} to {1}", args.Host, args.Address);