#import "NetworkController.h"
#import "MainController.h"
-#import "netinet/in.h"
-#import "arpa/inet.h"
#import <ITFoundation/ITDebug.h>
#import <ITFoundation/ITFoundation.h>
#import <ITMTRemote/ITMTRemote.h>
- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didFindService:(NSNetService *)aNetService moreComing:(BOOL)moreComing
{
+ ITDebugLog(@"Found service named %@.", [aNetService name]);
+ [remoteServices addObject:aNetService];
[aNetService setDelegate:self];
[aNetService resolve];
- ITDebugLog(@"Found service named %@.", [aNetService name]);
+ if (!moreComing) {
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"ITMTFoundNetService" object:nil];
+ }
+}
+
+- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didRemoveService:(NSNetService*)aNetService moreComing:(BOOL)moreComing
+{
+ ITDebugLog(@"Removed service named %@.", [aNetService name]);
+ [remoteServices removeObject:aNetService];
if (!moreComing) {
[[NSNotificationCenter defaultCenter] postNotificationName:@"ITMTFoundNetService" object:nil];
}
- (void)netServiceDidResolveAddress:(NSNetService *)sender
{
- [remoteServices addObject:[NSDictionary dictionaryWithObjectsAndKeys:[sender name], @"name",
- [NSString stringWithCString:inet_ntoa((*(struct sockaddr_in*)[[[sender addresses] objectAtIndex:0] bytes]).sin_addr)], @"ip",
- nil, nil]];
ITDebugLog(@"Resolved service named %@.", [sender name]);
- NSLog(@"found!");
+ NSLog(@"Resolved service named %@.", [sender name]);
[[NSNotificationCenter defaultCenter] postNotificationName:@"ITMTFoundNetService" object:nil];
}