main.m 1.08 KB
Newer Older
O'Reilly Media, Inc. committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#import <Foundation/Foundation.h>

@interface MyBrowser : NSObject
	{
	NSNetServiceBrowser *serviceBrowser;
	}
- (void)browseForServices;

@end

@implementation MyBrowser

- (void)browseForServices
	{
	serviceBrowser = [[NSNetServiceBrowser alloc] init];
	[serviceBrowser setDelegate:self];
	[serviceBrowser searchForServicesOfType:@"_example._tcp." inDomain:@""];
	}

- (void)netServiceBrowserWillSearch:(NSNetServiceBrowser *)aNetServiceBrowser
	{
	NSLog(@"Starting to search . . .\n");
	}


- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser
		didFindService:(NSNetService *)s moreComing:(BOOL)moreComing
	{
	NSLog(@"Add %@.%@%@\n", [s name], [s type], [s domain]);
	}


- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser
		didRemoveService:(NSNetService *)s moreComing:(BOOL)moreComing
	{
	NSLog(@"Rmv %@.%@%@\n", [s name], [s type], [s domain]);
	}

@end

int main(int argc, char *argv[])
	{
	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
	[[[MyBrowser alloc]init] browseForServices];
	[[NSRunLoop currentRunLoop] run];
	[pool release];
	return 0;
	}