1.1 --- a/BLIP/Demo/BLIPEchoClient.m Sun May 25 10:28:26 2008 -0700
1.2 +++ b/BLIP/Demo/BLIPEchoClient.m Wed Jun 04 17:11:20 2008 -0700
1.3 @@ -10,7 +10,6 @@
1.4
1.5 #import "BLIPEchoClient.h"
1.6 #import "BLIP.h"
1.7 -#import "IPAddress.h"
1.8 #import "Target.h"
1.9
1.10
1.11 @@ -28,24 +27,6 @@
1.12 }
1.13
1.14 #pragma mark -
1.15 -#pragma mark BLIPConnection support
1.16 -
1.17 -/* Opens a BLIP connection to the given address. */
1.18 -- (void)openConnection: (IPAddress*)address
1.19 -{
1.20 - _connection = [[BLIPConnection alloc] initToAddress: address];
1.21 - [_connection open];
1.22 -}
1.23 -
1.24 -/* Closes the currently open BLIP connection. */
1.25 -- (void)closeConnection
1.26 -{
1.27 - [_connection close];
1.28 - [_connection release];
1.29 - _connection = nil;
1.30 -}
1.31 -
1.32 -#pragma mark -
1.33 #pragma mark NSNetServiceBrowser delegate methods
1.34
1.35 // We broadcast the willChangeValueForKey: and didChangeValueForKey: for the NSTableView binding to work.
1.36 @@ -67,43 +48,24 @@
1.37 }
1.38
1.39 #pragma mark -
1.40 -#pragma mark NSNetService delegate methods
1.41 +#pragma mark BLIPConnection support
1.42
1.43 -/* Stop any current Bonjour address resolution */
1.44 -- (void)stopResolving
1.45 +/* Opens a BLIP connection to the given address. */
1.46 +- (void)openConnection: (NSNetService*)service
1.47 {
1.48 - if( _resolvingService ) {
1.49 - _resolvingService.delegate = nil;
1.50 - [_resolvingService stop];
1.51 - [_resolvingService release];
1.52 - _resolvingService = nil;
1.53 - }
1.54 -}
1.55 -
1.56 -/* Ask Bonjour to resolve (look up) the IP address of the given service. */
1.57 -- (void)startResolving: (NSNetService*)service
1.58 -{
1.59 - [self stopResolving];
1.60 - _resolvingService = [service retain];
1.61 - _resolvingService.delegate = self;
1.62 - [_resolvingService resolveWithTimeout: 5.0];
1.63 -
1.64 + _connection = [[BLIPConnection alloc] initToNetService: service];
1.65 + if( _connection )
1.66 + [_connection open];
1.67 + else
1.68 + NSBeep();
1.69 }
1.70
1.71 -/* NSNetService delegate method that will be called when address resolution finishes. */
1.72 -- (void)netServiceDidResolveAddress:(NSNetService *)sender
1.73 +/* Closes the currently open BLIP connection. */
1.74 +- (void)closeConnection
1.75 {
1.76 - if( sender == _resolvingService ) {
1.77 - // Get the first address, which is an NSData containing a struct sockaddr:
1.78 - NSArray *addresses = _resolvingService.addresses;
1.79 - if( addresses.count > 0 ) {
1.80 - NSData *addressData = [addresses objectAtIndex: 0];
1.81 - IPAddress *address = [[IPAddress alloc] initWithSockAddr: addressData.bytes];
1.82 - [self openConnection: address];
1.83 - [address release];
1.84 - }
1.85 - [self stopResolving];
1.86 - }
1.87 + [_connection close];
1.88 + [_connection release];
1.89 + _connection = nil;
1.90 }
1.91
1.92 #pragma mark -
1.93 @@ -114,17 +76,14 @@
1.94 int selectedRow = [table selectedRow];
1.95
1.96 [self closeConnection];
1.97 - [self stopResolving];
1.98 -
1.99 - if (-1 != selectedRow) {
1.100 - [self startResolving: [_serviceList objectAtIndex:selectedRow]];
1.101 - }
1.102 + if (-1 != selectedRow)
1.103 + [self openConnection: [_serviceList objectAtIndex:selectedRow]];
1.104 }
1.105
1.106 /* Send a BLIP request containing the string in the textfield */
1.107 - (IBAction)sendText:(id)sender
1.108 {
1.109 - BLIPRequest *r = [_connection requestWithBody: nil];
1.110 + BLIPRequest *r = [_connection request];
1.111 r.bodyString = [sender stringValue];
1.112 BLIPResponse *response = [r send];
1.113 response.onComplete = $target(self,gotResponse:);