• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Distributed Objects and Bonjour
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Distributed Objects and Bonjour


  • Subject: Re: Distributed Objects and Bonjour
  • From: "Adam R. Maxwell" <email@hidden>
  • Date: Wed, 28 Jun 2006 07:35:26 -0700


On Jun 26, 2006, at 11:37, Robert Sesek wrote:

Hello,

I'm trying to get Distributed Objects and Bonjour to work together. I've found various examples of these two items working independently, but I cannot seem to get them to work together.

I'll assume that the two methods you've posted are from different objects, since they both assign to a "connection" ivar. If not, you have big problems.



TI can broadcast and browse my Bonjour service and I setup my D-O system like this:


- (void)startDistributedObject
{
	connection = [NSConnection connectionWithReceivePort: socket
												sendPort: nil];
	[connection setRootObject: [manager dbConnector]];
	[[NSSocketPortNameServer sharedInstance] registerPort: socket
													 name: @"TindexServer"];
}

You need to retain the connection ivar here.

In the client, I browse for services and I have an NSMutableArray of NSNetService's that are of the service type _tindex._tcp. When somebody wants to connect to the server this method is executed (by clicking on a button):

This sounds reasonable...


- (IBAction)connectToServer: (id)sender
{
id proxy;
NSData *addy;

if ([serverList indexOfSelectedItem] != 0)
{
netService = [servers objectForKey: [serverList titleOfSelectedItem]];
NSLog(@"selected service: %@", netService);

socket = [[NSSocketPortNameServer sharedInstance] portForName: @"TindexServer"
host: [netService name]];
connection = [NSConnection connectionWithReceivePort: nil
sendPort: socket];
//proxy = [connection rootProxy];
addy = [socket address];

NSLog(@"socket = %@", socket);
NSLog(@"ipaddy = %@", [socket address]);
NSLog(@"connection = %@", connection);
//NSLog(@"proxy = %@", proxy);
}
else
{
NSLog(@"Current selection: <none>");
}
}


This above is the problemed code. I have no idea why this isn't working. When I uncomment the two lines above, then I get a crash. I've tried searching for so many examples, but can't find anything that works.

Here again, you need to retain connection if it's an ivar. Also, you need to run the call to -rootProxy inside an exception handler, and catch any exceptions raised (timeouts are common).


@try{
   proxy = [connection rootProxy];
}
@catch(id exception){
   proxy = nil;
   NSLog(@"caught exception \"%@\"", exception);
}

Your NSLog of proxy will likely crash since you didn't initialize the local variable to nil, as well. Having netService as an ivar assigned here doesn't make sense, either.

If you're interested in sample code, we added a sharing feature to BibDesk recently that uses DO over Bonjour for iTunes/iPhoto-style sharing, and it seems to work well.

Code is available at

// abstract class for background client/server
<https://svn.sourceforge.net/svnroot/bibdesk/trunk/bibdesk/ BDSKAsynchronousDOServer.m>


// concrete subclass for server
<https://svn.sourceforge.net/svnroot/bibdesk/trunk/bibdesk/ BDSKSharingServer.m>


// concrete subclass for client
<https://svn.sourceforge.net/svnroot/bibdesk/trunk/bibdesk/ BDSKSharedGroup.m>


// browser class that looks for servers on Bonjour
<https://svn.sourceforge.net/svnroot/bibdesk/trunk/bibdesk/ BDSKSharingBrowser.m>


This stuff is all BSD licensed; there aren't many (any?) DO/Bonjour sample code projects, so maybe something here will be useful to you, although the full project is moderately complicated. You can download and try it for yourself to see how it works, and bug reports are welcome, of course.

--
Adam
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Distributed Objects and Bonjour (From: Robert Sesek <email@hidden>)

  • Prev by Date: Sorting ABPerson array with NSSortDescriptors
  • Next by Date: Terminate File Copy
  • Previous by thread: Re: Distributed Objects and Bonjour
  • Next by thread: Re: Distributed Objects and Bonjour
  • Index(es):
    • Date
    • Thread