Give me a B! Give me a U! Give me a G!
[ITFoundation.git] / ITServiceBrowserDelegate.m
1 //
2 //  ITServiceBrowserDelegate.m
3 //  ITFoundation
4 //
5 //  Created by Alexander Strange on Sat Mar 15 2003.
6 //  Copyright (c) 2003 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "ITServiceBrowserDelegate.h"
10 #import "ITInetSocket.h"
11 #import <Foundation/NSNetServices.h>
12
13 @implementation ITServiceBrowserDelegate
14 - (id) initWithDelegate:(id)_delegate
15 {
16     if (self = [super init])
17            {
18            delegate = [_delegate retain];
19            }
20     return self;
21 }
22
23 - (void) dealloc
24 {
25     [delegate release];
26 }
27
28 - (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didFindService:(NSNetService *)aNetService moreComing:(BOOL)moreComing
29 {
30     ITInetSocket *sock;
31     NSArray *arr;
32     id d = delegate;
33     if (!moreComing)
34            {
35            NSLog(@"Nothing more coming");
36            [[aNetService retain] autorelease];
37            [aNetServiceBrowser stop];
38            [aNetServiceBrowser release];
39            [self release];
40            }
41     sock = [[ITInetSocket alloc] initWithDelegate:d];
42     NSLog(@"Detected a service! name %@ type %@",[aNetService name],[aNetService type]);
43     arr = [aNetService addresses];
44     if ([arr count])
45            [sock connectWithSockaddrArray:arr];
46     else
47            NSLog(@"There are no sockaddrs for this service!");
48 }
49
50 @end