On Sep 28, 2010, at 1:23 PM, Oleg Krupnov wrote:

> So, let's assume I create the connection in this way:
> 
> NSConnection* connection = [NSConnection connectionWithReceivePort:nil
> sendPort:[[NSMachBootstrapServer sharedInstance] portForName:@"foo"]];
> 
> or even
> 
> NSConnection* connection = [NSConnection
> connectionWithReceivePort:[NSMachPort port] sendPort:[NSMachPort
> port]];
> 
> Then I vend the object:
> 
> [connection setRootObject:serverObject];
> 
> And finally launch it in a separate thread:
> 
> [connection runInNewThread];
> 
> But how do I pass this connection back to client so that I could call
> -rootProxy on it?

You don't.  Please reread what I wrote.  My last email was largely about how 
the client creates its connection.  You've misunderstood it to be about how the 
server creates it.  (The above approaches wouldn't even work for a server.)

Servers don't create connections to clients.  Clients create connections to 
servers.

A server only explicitly creates a single NSConnection instance.  This isn't a 
connection so much as a "connection point" -- a place where clients can connect 
to.

Then, clients create connections to the server.  In response, in the server, 
the frameworks implicitly create new NSConnection instances for each client 
connection.  Once again, this is clearly illustrated in the documentation on 
Distributed Objects.  Have you read it?
<http://developer.apple.com/library/mac/#documentation/cocoa/Conceptual/DistrObjects/Concepts/connections.html>

We've already discussed how and when the server tells the newly-created 
connections to run in a separate thread.

The only complication is that, because your clients are attempting to make 
multiple connections from the same process, and because the frameworks try to 
reuse connections within a process, you have to take some minor extra 
precautions to make sure you are getting separate, independent connections to 
the server.  I have told you how to do that.

> That was actually the original question in the
> subject of this mail :)

Not as I understood it.  And if it was, then you have a fundamental 
misunderstanding about how connections work.  Again: servers don't create 
connections to clients; clients create connections to servers.

> The other question I've got is how do I exit the newly created thread
> when its job is done?

It should exit when the connection from the client closes.  It's possible that 
the server will have to explicitly -invalidate the connection in response to a 
sign-off message from the client.

Regards,
Ken

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to