diff -r 2bd9d60a2c46 -r 84c2d38f924c BLIP/Demo/BLIPEchoClient.m --- a/BLIP/Demo/BLIPEchoClient.m Sun May 25 10:28:26 2008 -0700 +++ b/BLIP/Demo/BLIPEchoClient.m Wed Jun 04 17:11:20 2008 -0700 @@ -10,7 +10,6 @@ #import "BLIPEchoClient.h" #import "BLIP.h" -#import "IPAddress.h" #import "Target.h" @@ -28,24 +27,6 @@ } #pragma mark - -#pragma mark BLIPConnection support - -/* Opens a BLIP connection to the given address. */ -- (void)openConnection: (IPAddress*)address -{ - _connection = [[BLIPConnection alloc] initToAddress: address]; - [_connection open]; -} - -/* Closes the currently open BLIP connection. */ -- (void)closeConnection -{ - [_connection close]; - [_connection release]; - _connection = nil; -} - -#pragma mark - #pragma mark NSNetServiceBrowser delegate methods // We broadcast the willChangeValueForKey: and didChangeValueForKey: for the NSTableView binding to work. @@ -67,43 +48,24 @@ } #pragma mark - -#pragma mark NSNetService delegate methods +#pragma mark BLIPConnection support -/* Stop any current Bonjour address resolution */ -- (void)stopResolving +/* Opens a BLIP connection to the given address. */ +- (void)openConnection: (NSNetService*)service { - if( _resolvingService ) { - _resolvingService.delegate = nil; - [_resolvingService stop]; - [_resolvingService release]; - _resolvingService = nil; - } -} - -/* Ask Bonjour to resolve (look up) the IP address of the given service. */ -- (void)startResolving: (NSNetService*)service -{ - [self stopResolving]; - _resolvingService = [service retain]; - _resolvingService.delegate = self; - [_resolvingService resolveWithTimeout: 5.0]; - + _connection = [[BLIPConnection alloc] initToNetService: service]; + if( _connection ) + [_connection open]; + else + NSBeep(); } -/* NSNetService delegate method that will be called when address resolution finishes. */ -- (void)netServiceDidResolveAddress:(NSNetService *)sender +/* Closes the currently open BLIP connection. */ +- (void)closeConnection { - if( sender == _resolvingService ) { - // Get the first address, which is an NSData containing a struct sockaddr: - NSArray *addresses = _resolvingService.addresses; - if( addresses.count > 0 ) { - NSData *addressData = [addresses objectAtIndex: 0]; - IPAddress *address = [[IPAddress alloc] initWithSockAddr: addressData.bytes]; - [self openConnection: address]; - [address release]; - } - [self stopResolving]; - } + [_connection close]; + [_connection release]; + _connection = nil; } #pragma mark - @@ -114,17 +76,14 @@ int selectedRow = [table selectedRow]; [self closeConnection]; - [self stopResolving]; - - if (-1 != selectedRow) { - [self startResolving: [_serviceList objectAtIndex:selectedRow]]; - } + if (-1 != selectedRow) + [self openConnection: [_serviceList objectAtIndex:selectedRow]]; } /* Send a BLIP request containing the string in the textfield */ - (IBAction)sendText:(id)sender { - BLIPRequest *r = [_connection requestWithBody: nil]; + BLIPRequest *r = [_connection request]; r.bodyString = [sender stringValue]; BLIPResponse *response = [r send]; response.onComplete = $target(self,gotResponse:);