I tried that but this also fails, slightly differently though.

One point seems to be that -isValid does not seem to be correct. When I
check this in BibDesk, it also returns NO, but we know it works. BTW, the
port in your code is not nil.

When I try my proposal, the it seems to work, including an NSConnection.
However when I try to send a DO message I get a log (not an exception)
saying

*** NSDistantObject initWithCoder: 0x2 not given away for conn 0x113140

Christiaan


On Sat, Aug 1, 2009 at 1:15 AM, Christiaan Hofman <cmhof...@gmail.com>wrote:

> I don't think you can use NSSocketPortNameServer for this. The problem is
> that NSSocketPortNameServer only looks for type _nsnetservice._tcp, while
> the NSNetService registers the port for type _bdsk._tcp. I think to connect
> back somehow you need to look up the port yourself, perhaps using the
> address of the NSNetService. Something like getting the port and family from
> the address and getting the NSSocketPort from there, like in the second
> sample on <http://www.cocoadev.com/index.pl?DistributedObjectsAndBonjour>.
>
> Christiaan
>
>
> On Aug 1, 2009, at 1:01 AM, Maxwell, Adam R wrote:
>
>  I tried using an NSSocketPort to get a port for the NSNetService and DO,
>> just out of curiosity.  This code creates a service that shows up in the
>> browse list, until I added the final assertion.  So receivePort is still
>> valid, but the NSSocketPortNameServer returns a port that's not valid (or
>> maybe nil...I didn't check).
>>
>> So even if there is a way to make it work by eliminating
>> NSSocketPortNameServer, I'd hate to say whether it worked by accident or
>> design, DO being what it is :).
>>
>> #import <Foundation/Foundation.h>
>> #import <sys/socket.h>
>> #include <netinet/in.h>
>> #include <unistd.h>
>>
>> int main (int argc, char const *argv[])
>> {
>>   NSAutoreleasePool *pool = [NSAutoreleasePool new];
>>
>>   NSString *sharingName = @"DO test name";
>>   NSPort *receivePort = [NSSocketPort port];
>>
>>   BOOL didRegister = [receivePort isValid] && [[NSSocketPortNameServer
>> sharedInstance] registerPort:receivePort name:sharingName];
>>   NSCParameterAssert(didRegister);
>>
>>   int fd = [(NSSocketPort *)receivePort socket];
>>   NSCParameterAssert(fd >= 0);
>>
>>   const struct sockaddr_in *saddr = [[(NSSocketPort *)receivePort address]
>> bytes];
>>
>>   uint16_t port = ntohs(saddr->sin_port);
>>   NSLog(@"port = %d", port);
>>
>>   NSNetService *service = [[NSNetService alloc] initWithDomain:@""
>> type:@"_bdsk._tcp." name:sharingName port:port];
>>
>>   NSMutableDictionary *dictionary = [NSMutableDictionary
>> dictionaryWithCapacity:4];
>>   [dictionary setObject:@"0" forKey:@"txtvers"];
>>   [dictionary setObject:@"NO" forKey:@"authenticate"];
>>   [dictionary setObject:@"dummy" forKey:@"ident"];
>>
>>   [service setTXTRecordData:[NSNetService
>> dataFromTXTRecordDictionary:dictionary]];
>>   [service publishWithOptions:0];
>>
>>   NSCParameterAssert([receivePort isValid]);
>>   NSCParameterAssert([[[NSSocketPortNameServer sharedInstance]
>> portForName:sharingName] isValid]);
>>
>>   [[NSRunLoop currentRunLoop] run];
>>
>>   [pool drain];
>>   return 0;
>> }
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Let Crystal Reports handle the reporting - Free Crystal Reports 2008
>> 30-Day
>> trial. Simplify your report design, integration and deployment - and focus
>> on
>> what you do best, core application coding. Discover what's new with
>> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
>> _______________________________________________
>> Bibdesk-develop mailing list
>> Bibdesk-develop@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/bibdesk-develop
>>
>
>
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Bibdesk-develop mailing list
Bibdesk-develop@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bibdesk-develop

Reply via email to