BLIP/Demo/BLIPEchoClient.m
changeset 5 2c4bb6968927
parent 3 76f302097a75
child 7 5936db2c1987
     1.1 --- a/BLIP/Demo/BLIPEchoClient.m	Sat May 24 21:26:09 2008 -0700
     1.2 +++ b/BLIP/Demo/BLIPEchoClient.m	Sun May 25 12:32:47 2008 -0700
     1.3 @@ -4,7 +4,8 @@
     1.4  //
     1.5  //  Created by Jens Alfke on 5/24/08.
     1.6  //  Copyright 2008 Jens Alfke. All rights reserved.
     1.7 -//  Adapted from Apple sample code "CocoaEcho".
     1.8 +//  Adapted from Apple sample code "CocoaEcho":
     1.9 +//  http://developer.apple.com/samplecode/CocoaEcho/index.html
    1.10  //
    1.11  
    1.12  #import "BLIPEchoClient.h"
    1.13 @@ -29,12 +30,14 @@
    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 @@ -66,6 +69,7 @@
    1.29  #pragma mark -
    1.30  #pragma mark NSNetService delegate methods
    1.31  
    1.32 +/* Stop any current Bonjour address resolution */
    1.33  - (void)stopResolving
    1.34  {
    1.35      if( _resolvingService ) {
    1.36 @@ -76,6 +80,7 @@
    1.37      }
    1.38  }    
    1.39  
    1.40 +/* Ask Bonjour to resolve (look up) the IP address of the given service. */
    1.41  - (void)startResolving: (NSNetService*)service
    1.42  {
    1.43      [self stopResolving];
    1.44 @@ -85,9 +90,11 @@
    1.45      
    1.46  }
    1.47  
    1.48 +/* NSNetService delegate method that will be called when address resolution finishes. */
    1.49  - (void)netServiceDidResolveAddress:(NSNetService *)sender
    1.50  {
    1.51      if( sender == _resolvingService ) {
    1.52 +        // Get the first address, which is an NSData containing a struct sockaddr:
    1.53          NSArray *addresses = _resolvingService.addresses;
    1.54          if( addresses.count > 0 ) {
    1.55              NSData *addressData = [addresses objectAtIndex: 0];
    1.56 @@ -114,6 +121,7 @@
    1.57      }
    1.58  }
    1.59  
    1.60 +/* Send a BLIP request containing the string in the textfield */
    1.61  - (IBAction)sendText:(id)sender 
    1.62  {
    1.63      BLIPRequest *r = [_connection requestWithBody: nil];
    1.64 @@ -122,6 +130,7 @@
    1.65      response.onComplete = $target(self,gotResponse:);
    1.66  }
    1.67  
    1.68 +/* Receive the response to the BLIP request, and put its contents into the response field */
    1.69  - (void) gotResponse: (BLIPResponse*)response
    1.70  {
    1.71      [responseField setObjectValue: response.bodyString];