Re: NSConnection not working between processes
Re: NSConnection not working between processes
- Subject: Re: NSConnection not working between processes
- From: James Bucanek <email@hidden>
- Date: Thu, 23 Jun 2005 08:06:43 -0700
Aurélien Hugelé wrote on Thursday, June 23, 2005:
> // Create a connection using two arbitrary ports
>> clientConnection = [NSConnection connectionWithReceivePort:
>> [NSPort port] sendPort:[NSPort port]];
>
>
>i suspected the probleme to be there... i tried
>clientConnection = [[NSConnection defaultConnection] retain]; and
>your program worked !
Thanks for looking into this. Yes, defaultConnection works in getting the helper's object vended to the client.
I guess I should have included more details from my previous post. My NSConnection must also acquire the proxy for the object vended by the client, which it uses to send asynchronous progress messages. (I didn't demonstrate this part of the problem in the example project, because I was trying to keep it simple).
I originally using defaultConnection when I first wrote this and was successful in vended the object to the client. This is when I ran into my first problem. If you read the fine print for defaultConnection you find this:
The default NSConnection uses a single NSPort for both receiving and sending
and is useful only for vending an object;
And they aren't kidding. The helper can use an NSConnection created with defaultConnection to vend an object to a remote NSConnection. But since it's only half an NSConnection, the helper can't access the object vended by the remote connection. The effect being that the helper can't send the client messages. If the helper calls [NSConnection rootProxy], it gets its own rootObject, not the proxy for the rootObject set by the client.
The only constructor that I could find which will create an as-yet-unnamed bidirectional NSConnection is connectionWithReceivePort:sendPort:.
So far my choices are use defaultConnection, in which case I can't get an object from the client to the helper, or use connectionWithReceivePort:sendPort:, in which case I can't get an object from the helper to the client. *sigh*
>i've never succeeded to completely understand NSPort,
You and me both! ;)
>so i can not explain you why your solution does not work... reading the doc
>mames me think everything is ok... but using higher level method seems
>"better"...
What's so infuriating is that I don't get any error messages or problems, yet the connection simply doesn't work. The connection gets named and is successfully registered with the NSPortNameServer, and the client finds the named connection and connects to it. Why nothing between the two connections work is a complete mystery to me.
>By the way, i think you forgot to retain the connection since
>[NSConnection connectionWithReceivePort: [NSPort port] sendPort:
>[NSPort port]]; returns an autoreleased object...
>
>>
>> // Register the connection
>> if ([clientConnection registerName:kDOPortName]==NO)
>> [[NSException exceptionWithName:@"Comm" reason:@"cannot
>> register NSConnection" userInfo:nil] raise];
In this case it's OK. Note that this method is called from main(), which isn't running in an event loop. This method "hangs" until the connection, and helper, is all done. So the autorelease pool created inside main() doesn't get released until this method returns -- which happens about 1ms before the process terminates.
One more note: Thinking this might be my problem, I rewrote my code to run this method in its own run loop ([NSRunLoop run]), instead of calling [NSConnection runInNewThread]. It made no detectable difference in the problem.
--
James Bucanek <mailto:email@hidden>
_______________________________________________
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