TweetFollow Us on Twitter

Using Rendezvous

Volume Number: 19 (2003)
Issue Number: 7
Column Tag: Cocoa

Using Rendezvous

How to discover and publish services on the LAN

by Wolfgang Ante

What is Rendezvous?

To start with a buzzword: Rendezvous is zero-config networking. That means using Rendezvous you should not have to set up any server addresses, user names, and such to access and use services on the local network. Just use them. Apple users not switching over from Windows recently already know this: AppleTalk supported zero-config networking from the beginning. So why is Rendezvous better?

First, Rendezvous is based on IP networking. IP is the industry standard, the Internet protocol, and has far less overhead than most other protocols. On the other hand AppleTalk is a proprietary protocol with a lot of overhead, making it more expensive and slower.

Second, Rendezvous is open. The source code is available for download and you may include it into your software for free. You will not need this as long as your program is running on Mac OS X only. But for developers on Linux and Windows this means they can use Rendezvous, too. If you take a look at the Rendezvous mailing list you can easily see that they do.

Publishing and browsing services

When your applications wants to provide a service on the network you will have to publish it, when you want to use a service published by someone else you will have to browse for services. A service is whatever you want it to be. Rendezvous is just helping to announce and find services. It gives you all you need to connect, namely the IP address and port number, but doesn't setup the connection itself.

Cocoa gives you a very powerful way to connect to other Cocoa applications on the network called Distributed Objects. My next article will be on Distributed Objects, but for now let's get into the details of using Rendezvous in code.

Goals

I noticed that Rendezvous is not widely adopted yet, and after working with it myself I think I know why: You still have to care about a lot of things you are not very much interested in, even in Cocoa. Don't get me wrong, I think the Cocoa API to Rendezvous is very good, but for 90% of the applications that could use Rendezvous it would be very handy to have something that gives you just two things: The ability to publish a service and to browse for others who published the same type of service in one easy to use class.

This article will show you how Rendezvous works and additionally will give you a simplified interface (the ARendezvousController class) that you are free to use in your software. Using Rendezvous will open your application for teamwork. Think about it, in a lot of applications it makes sense to connect and communicate!

Overview

Cocoa gives you two classes for the two main objectives: NSNetService to publish services and NSNetServiceBrowser to browse published services.

Because network operations may take some time to finish, both classes use the concept of delegation to keep your application responsive. You ask for what you want and continue. As soon as the information is available your delegate will be notified about the found information. This also solves the problem of dynamic changes, when services are published or removed later on. Every time the situation changes your delegate will be notified.

There are quite a lot of delegation methods that make understanding the API confusing at first. I will try to concentrate on a typical flow of information, if you are interested in the complete list of delegation methods later, I recommend using the freeware "AppKiDo" from Andy Lee. It is a very good Cocoa API browser, I could not live without it anymore. It is available at <http://homepage.mac.com/aglee/downloads>.

Publishing

Publishing a service is quite easy. You create a service by creating an object of type NSNetService, set the delegate and publish the service. Listing 1 shows this:

Listing 1:

Publishing

NSNetService  *service;
NSString      *publishedName;
Int           portNumber;

service = [[NSNetService alloc] initWithDomain:@""
  type:@"_servicetype._tcp."
  name:publishedName
  port:portNumber];
[service setDelegate:delegate];
[service publish];

To publish on the default domain (which is the 'local' domain, i.e. your LAN) you pass an empty string to initWithDomain. type is an identifier for the kind of service you are publishing. The naming convention for this is "_servicetype._tcp." where you replace servicetype with your identifier. The type is usually not visible to the user, so be as clear or obscure as you like. name identifies your service to the network and must be unique. The name usually is visible to the user. Finally port must contain a port number you already acquired for the service.

setDelegate sets the delegate, this is the object that will be notified later. publish will start the process. As soon as you publish your service it will broadcast its presence on the network.

The only interesting delegate method at this point is netService:didNotPublish:. This will be sent to your delegate when the service could not be published, otherwise you can assume that your service has been published and is visible to others now.

Browsing

Browsing for services is a bit more complicated. You start by creating an object of type NSNetServiceBrowser, set the delegate and start browsing. Listing 2 shows this:

Listing 2:

Start browsing

NSNetServiceBrowser *browser;

browser = [[NSNetServiceBrowser alloc] init];
[browser setDelegate:self];
[browser searchForServicesOfType:@"_servicetype._tcp."
  inDomain:@""];

First you create the object and set the delegate to be notified, then you start browsing by asking for services of the type you are interested in. As before pass an empty string to browse in the default domain.

Again the requested information will be sent to your delegate later. The interesting ones that will be sent to you at this point are netServiceBrowser:didFindService:moreComing: and netServiceBrowser:didRemoveService:moreComing:. Rendezvous is dynamic, so services will show up and go away from time to time. As long as you do not stop browsing, your delegate will receive these messages every time something changes about the availability of services of the requested type on the network.

Lets start by looking at netServiceBrowser:didFindService:moreComing:. Listing 3 shows an implementation:

Listing 3:

Service found

- (void)netServiceBrowser:
  (NSNetServiceBrowser *)aNetServiceBrowser 
  didFindService:(NSNetService *)aNetService 
  moreComing:(BOOL)moreComing
{
    [aNetService setDelegate:self];
    [aNetService resolve];
}

You receive three parameters: aNetServiceBrowser is the browser that sent the message, aNetService is the service that has been found and moreComing tells you if there are more queued service objects. The moreComing parameter looks a bit strange at first, but can be used as a hint to your user interface code to delay updating.

The information you are probably most interested in comes as the second parameter and it looks like this is already everything you need. Unfortunately you only get one third of the information you are interested in. You can send the service object a name message to get the name of the service. To obtain the IP address and port number you have to set a delegate and send a resolve message to the service. Don't forget to set the delegate, since this time the service will sent you messages, not the browser. When you send resolve this will again result in messages sent to the delegate. The interesting one this time is netServiceDidResolveAddress:.

Following the successful path lets start by looking at netServiceDidResolveAddress:. Listing 4 shows an implementation:

Listing 4:

Addresses resolved

- (void)netServiceDidResolveAddress:(NSNetService *)sender
{
    NSString           *name = nil;
    NSData             *address = nil;
    struct sockaddr_in *socketAddress = nil;
    NSString           *ipString = nil;
    int                port;
    
    for (i = 0; i < [[sender addresses] count]; i++)
    {
        name = [sender name];
        address = [[sender addresses] objectAtIndex:i];
        socketAddress = (struct sockaddr_in *)
          [address bytes];
        ipString = [NSString stringWithFormat: @"%s",
          inet_ntoa (socketAddress->sin_addr)];
        port = socketAddress->sin_port;
        [...]
     }
}

The only parameter is the service object that sent the message. Now the service object holds all the needed information to connect to the service. You obtain the name by sending a name message to the service. To find the IP address and port number you send an addresses message to the service. You receive an array containing all addresses. This array usually contains exactly one address, but to be on the save side loop through all addresses in the array. An address is of type sockaddr_in. This is a standard networking structure of Unix. See the above code for the details. After you have the name, IP and port you are ready to use that information. You will probably store the information in an array so you can access it any time you need it.

Lets go one step back to netServiceBrowser:didRemoveService:moreComing:. This message will be sent to you every time a service has been removed. If you stored the information in an array you have to remove the entry for that service to keep the array up-to-date.

Browsing problems

On Mac OS X 10.2.3 and before there is a problem with service browsing and switching locations. When you switch the location from the Apple menu (or change your IP address in any other way) the browser gets seriously confused. Your old and new IP may or may not show up. You may get entries that are simply wrong, pointing to your old IP address.

This happens with Apple's Rendezvous-enabled products, too. I saw myself showing up in iChat double after switching back and forth and Apple's AFPServer (the 'Personal File Sharing' server) also has problems with it, when you look at your logs.

It might be that this is already fixed when you read this, since Apple has released fixes to Rendezvous with every of the last three system updates. I read it is much better with Mac OS X 10.2.5, but to be nice to your users you should try to offer them a workaround on systems before 10.2.5 at least.

My suggestion is to offer refresh functionality. A refresh starts a complete new search forgetting about the cached entries.

If you want to automate this, you could regularly check if your IP address has changed (use [[NSHost currentHost] address] for this) and then refresh. The ARendezvousController class does not do this, but it offers a refreshBrowsing method that you can hook up to a button in your user interface easily.

Making things easier

By now you have a good overview of how to use Rendezvous. But like me, I guess you will think that you don't want to weave that all into your code every time you want to use Rendezvous.

Therefore I came up with ARendezvousController. It has a simplified interface and still provides everything to publish and browse services. An ARendezvousController object cares about one service type, publishing and browsing it. It provides start/stop methods for publishing and browsing. It has exactly one delegate method that is called every time something changes. It keeps track of the found services and on request returns an array with all found services, ready with name, IP address and port number. It even creates the socket others will connect to for you.

Listing 5:

Public interface of ARendezvousController

// public interface
@interface ARendezvousController : NSObject

- (id)initWithName:(NSString *)name type:(NSString *)type
  port:(int)port;
- (void)dealloc;
- (id)delegate;
- (void)setDelegate:(id)object;
- (NSString *)name;
- (BOOL)setName:(NSString *)name;
- (NSSocketPort *)socket;

- (void)activateBrowsing:(BOOL)flag;
- (BOOL)isBrowsing;
- (void)refreshBrowsing;
- (void)activatePublishing:(BOOL)flag;
- (BOOL)isPublished;
- (NSArray *)discoveredServicesWithInfo;

- (NSString *)ipForName:(NSString *)name;
- (int)portForName:(NSString *)name;

@end

// to be implemented by the delegate
@interface NSObject (RendezvousControllerDelegate)

- (void)discoveredServicesDidChange:(id)sender;

@end

Using ARendezvousController

Instead of going through the list method by method, lets start with a real world example. The following code will fill an NSTableView with all available services of type @"_demo._tcp." on your local network. The table view will be updated dynamically every time services are published and removed without user intervention. Just like you know it from iChat.

The complete demo project including ARendezvousController can be downloaded from <http://www.artissoftware.com/rendezvous>. This is probably the best way to proceed, since you don't have to create the .nib file in Interface Builder yourself.

If you are reading this without access to the Internet, here is what you need to create in Interface Builder: The main window contains an NSTableView. The NSTableView has three columns. The identifiers of the three columns should be "name", "ip" and "port".

Listing 6:

ADemoController.h

@interface ADemoController : NSObject
{
    IBOutlet NSWindow     *_mainWindow;
    IBOutlet NSTableView  *_tableView;
    ARendezvousController    *_rendezvousController;
    NSArray                *_lastState;
}
- (void)awakeFromNib;
- (void)discoveredServicesDidChange:(id)sender;
- (int)numberOfRowsInTableView:(NSTableView *)tableView;
- (id)tableView:(NSTableView *)tableView
  objectValueForTableColumn:(NSTableColumn *)tableColumn
  row:(int)row;
@end

In Interface Builder import this header file and connect the _mainWindow outlet to your window and the _tableView outlet to your table view.

Lets start by looking at awakeFromNib. This methods contains all the necessary setup:

Listing 7:

awakeFromNib

- (void)awakeFromNib
{
    _lastState = [[NSArray alloc] init];
    _rendezvousController = [[ARendezvousController alloc]
      initWithName:NSFullUserName() type:@"_demo._tcp."
      port:12345];
    [_rendezvousController setDelegate:self];
    [_rendezvousController activateBrowsing:YES];
    [_rendezvousController activatePublishing:YES];
    [_mainWindow center];
    [_mainWindow makeKeyAndOrderFront:self];
}

_lastState will contain a copy of the last state returned by the rendezvousController. In the beginning there are no services, so it is initialized as an empty array. After that the ARendezvousController is initialized with a type of @"_demo._tcp." and with port 12345. The port number is just a suggestion. If this port is already in use the number is increased as long as a socket can be created. This is no problem, since the port number is published. At this time the socket will be created. To obtain the socket you would send a socket message to the rendezvousController. Finally the delegate is set to self so we are notified of changes, browsing is started by sending activateBrowsing: and the service is published by sending activatePublishing: to the rendezvousController.

The next method is the delegate method.

Listing 8:

The delegate method

- (void)discoveredServicesDidChange:(id)sender
{
    [_lastState autorelease];
    _lastState = [[rendezvousController
      discoveredServicesWithInfo] retain];
    [_tableView reloadData];
}

It simply releases the old copy of states, asks the rendezvousController for an up-to-date array of states and retains that. After that it tells the table view to reload its data.

Finally these two methods fill the table view with data:

Listing 9:

Tableview methods

- (int)numberOfRowsInTableView:(NSTableView *)tableView
{
    return [_lastState count];
}
- (id)tableView:(NSTableView *)tableView
  objectValueForTableColumn:(NSTableColumn *)tableColumn
  row:(int)row
{
    return [[_lastState objectAtIndex:row]
      valueForKey:[tableColumn identifier]];
}

The last one is a wonderful demonstration of applied Cocoa magic, but to understand it you should know first that the array returned by discoveredServicesWithInfo contains an NSDictionary for every service. Such a dictionary contains three key/value pairs:

Key "name" contains an NSString with the name of the service

Key "ip" contains an NSString with the IP address (like @"192.168.0.1")

Key "port" contains an NSNumber with the port number

By setting the column identifiers of the table view to these keys the data can be fed to the table view with this one-liner.

That's it! It is that simple. In my next article I will show how to send messages over the network just like you would send it to your objects. This is called Distributed Objects. Stay tuned!

Listing 10:

ARendezvousController.h

#import <Foundation/Foundation.h>
// interface of the rendezvous class
@interface ARendezvousController : NSObject
{
    NSNetService  *_service;
    NSString      *_serviceName;
    NSString      *_serviceType;
    BOOL          _browsing;
    BOOL          _publishing;
    NSNetServiceBrowser  *_serviceBrowser;
    NSNetServiceBrowser  *_domainBrowser;
    NSSocketPort         *_socketPort;
    int                  _portNumber;
    NSMutableArray       *_discoveredServicesWithInfo;
    id                   _delegate;
}
- (id)initWithName:(NSString *)name type:(NSString *)type
  port:(int)port;
- (void)dealloc;
- (id)delegate;
- (void)setDelegate:(id)object;
- (NSString *)name;
- (BOOL)setName:(NSString *)name;
- (NSSocketPort *)socket;
- (void)activateBrowsing:(BOOL)flag;
- (BOOL)isBrowsing;
- (void)refreshBrowsing;
- (void)activatePublishing:(BOOL)flag;
- (BOOL)isPublished;
- (NSArray *)discoveredServicesWithInfo;
- (NSString *)ipForName:(NSString *)name;
- (int)portForName:(NSString *)name;
@end
// to be implemented by the delegate
@interface NSObject (RendezvousControllerDelegate)
- (void)discoveredServicesDidChange:(id)sender;
@end

Listing 11:

ARendezvousController.m

#import "ARendezvousController.h"
#include <netinet/in.h>
#include <arpa/inet.h>
@interface ARendezvousController (ARendezvousControllerInternal)
// creation
- (void)createSocket;
- (void)createBrowser;
- (void)createService;
// management
- (BOOL)addInfoService:(NSNetService *)
  service name:(NSString *)name ip:(NSString *)ip
  port:(int)port;
- (BOOL)removeInfoService:(NSNetService *)service;
// other
- (void)startBrowsing;
@end
@interface ARendezvousController (NSNetServiceDelegation)
// publication
- (void)netService:(NSNetService *)sender
  didNotPublish:(NSDictionary *)errorDict;
- (void)netServiceWillPublish:(NSNetService *)sender;
- (void)netServiceDidStop:(NSNetService *)sender;
// resolution
- (void)netService:(NSNetService *)sender
  didNotResolve:(NSDictionary *)errorDict;
- (void)netServiceDidResolveAddress:(NSNetService *)sender;
- (void)netServiceWillResolve:(NSNetService *)sender;
@end
@interface ARendezvousController
  (NSNetServiceBrowserDelegation)
// browsing
- (void)netServiceBrowser:(NSNetServiceBrowser *)
  aNetServiceBrowser didFindService:(NSNetService *)
  aNetService moreComing:(BOOL)moreComing;
- (void)netServiceBrowser:(NSNetServiceBrowser *)
  aNetServiceBrowser didNotSearch:(NSDictionary *)errorDict;
- (void)netServiceBrowser:(NSNetServiceBrowser *)
  aNetServiceBrowser didRemoveService:(NSNetService *)
  aNetService moreComing:(BOOL)moreComing;
- (void)netServiceBrowser:(NSNetServiceBrowser *)
  aNetServiceBrowser didFindDomain:(NSString *)domainString
  moreComing:(BOOL)moreComing;
- (void)netServiceBrowser:(NSNetServiceBrowser *)
  aNetServiceBrowser didRemoveDomain:(NSString *)domainString 
  moreComing:(BOOL)moreComing;
- (void)netServiceBrowserDidStopSearch:
  (NSNetServiceBrowser *)aNetServiceBrowser;
- (void)netServiceBrowserWillSearch:
  (NSNetServiceBrowser *)aNetServiceBrowser;
@end
@implementation ARendezvousController
- (id)initWithName:(NSString *)name type:(NSString *)type
  port:(int)port
{
    self = [super init];
    if (self)
    {
        // store name, type and port for later
        [self setName:name];
        _serviceType = [type retain];
        _portNumber = port;
        
        // initialize array
        _discoveredServicesWithInfo =
          [[NSMutableArray alloc] init];
        
        // create the socket and the browser
        [self createSocket];
        [self createBrowser];
    }
    return self;
}
- (void)dealloc
{
    // clean up
    [self activatePublishing:NO];
    [_serviceBrowser stop];
    [_domainBrowser stop];
    [_socketPort release];
    [_discoveredServicesWithInfo release];
    [super dealloc];
}
- (id)delegate
{
    return _delegate;
}
- (void)setDelegate:(id)object
{
    // find if delegate supports the delegation message
    if (![object respondsToSelector:
      @selector(discoveredServicesDidChange:)])
        NSLog (@"Delegate does not respond to 
          'discoveredServicesDidChange:'!");
    
    _delegate = object;
}
- (NSString *)name
{
    return _serviceName;
}
- (BOOL)setName:(NSString *)name
{
    // change name only when not already published
    if (!_publishing)
    {
        [name retain];
        [_serviceName release];
        _serviceName = name;
        return YES;
    }
    else
    {
        NSLog (@"Cannot change name while service
          is published!");
        return NO;
    }
}
- (NSSocketPort *)socket
{
    return _socketPort;
}
- (void)activateBrowsing:(BOOL)flag
{
    // if requested and actual state match don't proceed
    if (flag == _browsing)
        return;
    
    if (flag)
    {
        // activate browsing
        _browsing = YES;
        [_serviceBrowser searchForServicesOfType:
          _serviceType inDomain:@""];
    }
    else
    {
        // deactivate browsing
        _browsing = NO;
        [_serviceBrowser stop];
        [_discoveredServicesWithInfo removeAllObjects];
        [_delegate discoveredServicesDidChange:self];
    }
}
- (BOOL)isBrowsing
{
    return _browsing;
}
- (void)startBrowsing
{
    // should only be called when browsing off
    if (_browsing)
    {
        NSLog (@"Browing already started!");
        return;
    }
    
    // start browsing
    _browsing = YES;
    [_serviceBrowser searchForServicesOfType:
      _serviceType inDomain:@""];
}
- (void)refreshBrowsing
{
    // don't refresh if not browsing
    if (!_browsing)
        return;
    
    // start/stop
    // (stop is deferred to the end of message queue)
    [self activateBrowsing:NO];
    [self performSelector:@selector(startBrowsing)
      withObject:nil afterDelay:0.0];
}
- (void)activatePublishing:(BOOL)flag
{
    // if already activated then don't do anything
    if (_publishing == flag)
        return;
    
    if (flag)
    {
        // activate service
        [self createService];
    }
    else
    {
        // deactivate service
        [_service stop];
        _service = nil;
    }
    
    // set new state
    _publishing = flag;
}
- (BOOL)isPublished
{
    return _publishing;
}
- (NSArray *)discoveredServicesWithInfo
{
    // return (autoreleased) copy
    return [NSArray 
      arrayWithArray:_discoveredServicesWithInfo];
}
- (NSString *)ipForName:(NSString *)name
{
    NSEnumerator    *e = nil;
    NSDictionary    *dict = nil;
    
    // find the corresponding ip to the given name
    e = [_discoveredServicesWithInfo objectEnumerator];
    while (dict = [e nextObject])
        if ([[dict objectForKey:@"name"]
          isEqualToString:name])
            return [dict objectForKey:@"ip"];
    
    // return nil when not found
    return nil;
}
- (int)portForName:(NSString *)name
{
    NSEnumerator    *e = nil;
    NSDictionary    *dict = nil;
    
    // find the corresponding ip to the given name
    e = [_discoveredServicesWithInfo objectEnumerator];
    while (dict = [e nextObject])
        if ([[dict objectForKey:@"name"]
          isEqualToString:name])
            return [[dict objectForKey:@"port"] intValue];
    
    // return 0 when not found
    return 0;
}
@end
@implementation ARendezvousController
  (RendezvousControllerInternal)
- (void)createSocket
{
    // already there
    if (_socketPort)
        return;
    
    // look for free port
    while (!_socketPort)
    {
        _socketPort = [[NSSocketPort alloc]
          initWithTCPPort:_portNumber];
        _portNumber++;
    }
    _portNumber--;
}
- (void)createService
{
    // already there
    if (_service)
        return;
    
    // create service, make self the delegate and publish
    _service = [[NSNetService alloc] initWithDomain:@""
      type:_serviceType name:_serviceName port:_portNumber];
    [_service setDelegate:self];
    [_service publish];
}
- (void)createBrowser
{
    // setup service browser
    if (!_serviceBrowser)
    {
        _serviceBrowser = [[NSNetServiceBrowser alloc] init];
        [_serviceBrowser setDelegate:self];
    }
}
- (BOOL)addInfoService:(NSNetService *)service name:(NSString *)name ip:(NSString *)ip port:(int)port
{
    NSMutableDictionary    *dict = nil;
    NSEnumerator           *e = nil;
    
    // if already there then don't add
    e = [_discoveredServicesWithInfo objectEnumerator];
    while (dict = [e nextObject])
        if ([[dict objectForKey:@"ip"] isEqualToString:ip])
            if ([[dict objectForKey:@"port"] intValue] ==
              port)
                return NO;
    
    // add if not found in array
    dict = [NSMutableDictionary dictionary];
    [dict setObject:ip forKey:@"ip"];
    [dict setObject:[NSNumber numberWithInt:port]
      forKey:@"port"];
    [dict setObject:name forKey:@"name"];
    [dict setObject:service forKey:@"service"];
    [_discoveredServicesWithInfo addObject:dict];
    return YES;
}
- (BOOL)removeInfoService:(NSNetService *)service
{
    NSDictionary    *dict = nil;
    NSEnumerator    *e = nil;
    NSMutableArray  *delete = nil;
    
    // look for object with this service and mark for delete
    delete =[NSMutableArray array];
    e = [_discoveredServicesWithInfo objectEnumerator];
    while (dict = [e nextObject])
        if ([[dict objectForKey:@"service"] isEqual:service])
            [delete addObject:dict];
    
    // delete marked objects
    e = [delete objectEnumerator];
    while (dict = [e nextObject])
        [_discoveredServicesWithInfo removeObject:dict];
    
    return NO;
}
@end
@implementation ARendezvousController
  (NSNetServiceDelegation)
- (void)netService:(NSNetService *)sender
  didNotPublish:(NSDictionary *)errorDict
{
    // publishing failed
    _publishing = NO;
    NSLog (@"Publishing the service %@failed.",
      [sender name]);
    [_delegate discoveredServicesDidChange:self];
}
- (void)netServiceWillPublish:(NSNetService *)sender
{
    // does nothing for now,
    // implemented for your possible additions
}
- (void)netServiceDidStop:(NSNetService *)sender
{
    // does nothing for now,
    // implemented for your possible additions
}
- (void)netService:(NSNetService *)sender didNotResolve:(NSDictionary *)errorDict
{
    // resolving failed
    NSLog (@"Resolving of address for service %@ failed.",
      [sender name]);
}
- (void)netServiceDidResolveAddress:(NSNetService *)sender
{
    NSData              *address = nil;
    struct sockaddr_in  *socketAddress = nil;
    NSString            *ipString = nil;
    int                 port, i;
    
    for (i = 0; i < [[sender addresses] count]; i++)
    {
        // gather data about this published service
        address = [[sender addresses] objectAtIndex:i];
        socketAddress = (struct sockaddr_in *)
          [address bytes];
        ipString = [NSString stringWithFormat: @"%s",
          inet_ntoa (socketAddress->sin_addr)];
        port = socketAddress->sin_port;
        
        // published localhost is a Rendezvous strangeness:
        // ignore that!
        if ([ipString isEqualToString:@"127.0.0.1"])
            continue;
        
        // notify delegate of change
        if ([self addInfoService:sender name:[sender name]
          ip:ipString port:port])
            [_delegate discoveredServicesDidChange:self];
    }
}
- (void)netServiceWillResolve:(NSNetService *)sender
{
    // does nothing for now,
    // implemented for your possible additions
}
@end
@implementation ARendezvousController
  (NSNetServiceBrowserDelegation)
- (void)netServiceBrowser:(NSNetServiceBrowser *)
  aNetServiceBrowser didFindService:(NSNetService *)
  aNetService moreComing:(BOOL)moreComing
{
    // add to dicovered services and resolve it
    [aNetService setDelegate:self];
    [aNetService resolve];
}
- (void)netServiceBrowser:(NSNetServiceBrowser *)
  aNetServiceBrowser didRemoveService:(NSNetService *)
  aNetService moreComing:(BOOL)moreComing
{
    // remove and notify
    [self removeInfoService:aNetService];
    [_delegate discoveredServicesDidChange:self];
}
- (void)netServiceBrowserDidStopSearch:
  (NSNetServiceBrowser *)aNetServiceBrowser
{
    // empty the arrays and notify delegate
    if (aNetServiceBrowser == _serviceBrowser)
    {
        [_discoveredServicesWithInfo removeAllObjects];
        [_delegate discoveredServicesDidChange:self];
    }
}
- (void)netServiceBrowser:(NSNetServiceBrowser *)
  aNetServiceBrowser didNotSearch:(NSDictionary *)errorDict
{
    NSLog (@"Unable to search.");
}
- (void)netServiceBrowserWillSearch:(NSNetServiceBrowser *)
  aNetServiceBrowser
{
    // does nothing for now,
    // implemented for your possible additions
}
- (void)netServiceBrowser:(NSNetServiceBrowser *)
  aNetServiceBrowser didFindDomain:(NSString *)domainString
  moreComing:(BOOL)moreComing
{
    // does nothing for now,
    // implemented for your possible additions
}
- (void)netServiceBrowser:(NSNetServiceBrowser *)
  aNetServiceBrowser didRemoveDomain:(NSString *)domainString 
  moreComing:(BOOL)moreComing
{
    // does nothing for now,
    // implemented for your possible additions
}
@end

Bibliography and References

Apple Computer. "Rendezvous Network Services" <http://developer.apple.com/techpubs/macosx/...>

Michael Beam. "Incorporating Rendezvous into Your Cocoa Applications"

<http://www.macdevcenter.com/pub/a/mac/2002/11/08/cocoa.html>


Wolfgang Ante is the founder of ARTIS Software (http://www.artissoftware.com). In the last 14 years he worked on Macintosh products for ARTIS and lots of other companies, including a product that won the Macworld's Editors Choice Award. At the time he is trying hard to transform ARTIS into a successful Mac OS X shareware company. Beside that he is always happy to offer his experience for working on your project. You can reach him at wolfgang@artissoftware.com.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Top Mobile Game Discounts
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links... | Read more »
Price of Glory unleashes its 1.4 Alpha u...
As much as we all probably dislike Maths as a subject, we do have to hand it to geometry for giving us the good old Hexgrid, home of some of the best strategy games. One such example, Price of Glory, has dropped its 1.4 Alpha update, stocked full... | Read more »
The SLC 2025 kicks off this month to cro...
Ever since the Solo Leveling: Arise Championship 2025 was announced, I have been looking forward to it. The promotional clip they released a month or two back showed crowds going absolutely nuts for the previous competitions, so imagine the... | Read more »
Dive into some early Magicpunk fun as Cr...
Excellent news for fans of steampunk and magic; the Precursor Test for Magicpunk MMORPG Crystal of Atlan opens today. This rather fancy way of saying beta test will remain open until March 5th and is available for PC - boo - and Android devices -... | Read more »
Prepare to get your mind melted as Evang...
If you are a fan of sci-fi shooters and incredibly weird, mind-bending anime series, then you are in for a treat, as Goddess of Victory: Nikke is gearing up for its second collaboration with Evangelion. We were also treated to an upcoming... | Read more »
Square Enix gives with one hand and slap...
We have something of a mixed bag coming over from Square Enix HQ today. Two of their mobile games are revelling in life with new events keeping them alive, whilst another has been thrown onto the ever-growing discard pile Square is building. I... | Read more »
Let the world burn as you have some fest...
It is time to leave the world burning once again as you take a much-needed break from that whole “hero” lark and enjoy some celebrations in Genshin Impact. Version 5.4, Moonlight Amidst Dreams, will see you in Inazuma to attend the Mikawa Flower... | Read more »
Full Moon Over the Abyssal Sea lands on...
Aether Gazer has announced its latest major update, and it is one of the loveliest event names I have ever heard. Full Moon Over the Abyssal Sea is an amazing name, and it comes loaded with two side stories, a new S-grade Modifier, and some fancy... | Read more »
Open your own eatery for all the forest...
Very important question; when you read the title Zoo Restaurant, do you also immediately think of running a restaurant in which you cook Zoo animals as the course? I will just assume yes. Anyway, come June 23rd we will all be able to start up our... | Read more »
Crystal of Atlan opens registration for...
Nuverse was prominently featured in the last month for all the wrong reasons with the USA TikTok debacle, but now it is putting all that behind it and preparing for the Crystal of Atlan beta test. Taking place between February 18th and March 5th,... | Read more »

Price Scanner via MacPrices.net

AT&T is offering a 65% discount on the ne...
AT&T is offering the new iPhone 16e for up to 65% off their monthly finance fee with 36-months of service. No trade-in is required. Discount is applied via monthly bill credits over the 36 month... Read more
Use this code to get a free iPhone 13 at Visi...
For a limited time, use code SWEETDEAL to get a free 128GB iPhone 13 Visible, Verizon’s low-cost wireless cell service, Visible. Deal is valid when you purchase the Visible+ annual plan. Free... Read more
M4 Mac minis on sale for $50-$80 off MSRP at...
B&H Photo has M4 Mac minis in stock and on sale right now for $50 to $80 off Apple’s MSRP, each including free 1-2 day shipping to most US addresses: – M4 Mac mini (16GB/256GB): $549, $50 off... Read more
Buy an iPhone 16 at Boost Mobile and get one...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering one year of free Unlimited service with the purchase of any iPhone 16. Purchase the iPhone at standard MSRP, and then choose... Read more
Get an iPhone 15 for only $299 at Boost Mobil...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering the 128GB iPhone 15 for $299.99 including service with their Unlimited Premium plan (50GB of premium data, $60/month), or $20... Read more
Unreal Mobile is offering $100 off any new iP...
Unreal Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering a $100 discount on any new iPhone with service. This includes new iPhone 16 models as well as iPhone 15, 14, 13, and SE... Read more
Apple drops prices on clearance iPhone 14 mod...
With today’s introduction of the new iPhone 16e, Apple has discontinued the iPhone 14, 14 Pro, and SE. In response, Apple has dropped prices on unlocked, Certified Refurbished, iPhone 14 models to a... Read more
B&H has 16-inch M4 Max MacBook Pros on sa...
B&H Photo is offering a $360-$410 discount on new 16-inch MacBook Pros with M4 Max CPUs right now. B&H offers free 1-2 day shipping to most US addresses: – 16″ M4 Max MacBook Pro (36GB/1TB/... Read more
Amazon is offering a $100 discount on the M4...
Amazon has the M4 Pro Mac mini discounted $100 off MSRP right now. Shipping is free. Their price is the lowest currently available for this popular mini: – Mac mini M4 Pro (24GB/512GB): $1299, $100... Read more
B&H continues to offer $150-$220 discount...
B&H Photo has 14-inch M4 MacBook Pros on sale for $150-$220 off MSRP. B&H offers free 1-2 day shipping to most US addresses: – 14″ M4 MacBook Pro (16GB/512GB): $1449, $150 off MSRP – 14″ M4... Read more

Jobs Board

All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.