Re: NSConnection question
Re: NSConnection question
- Subject: Re: NSConnection question
- From: Wade Tregaskis <email@hidden>
- Date: Wed, 8 Oct 2003 23:59:00 +1000
Can someone explain to me why this doesn4t work:
myServerAddress = @"localhost";
myServer = [NSConnection
rootProxyForConnectionWithRegisteredName:@"Server"
host:myServerAddress];
I would be grateful to all help!
The NSConnection convenience methods -
rootProxyForConnectionWithRegisteredName: being one of them - use mach
ports solely, not sockets. You could consider this a bug, since they
clearly allow you to provide a host name. Whether this is a bug or a
missing feature I can't recall, although it was discussed quite
recently on some mailing list (perhaps this one, or mac-network-prog,
or perhaps the Omni lists).
Anyway, if you want to use sockets, even if just connecting to the
local machine, you'll have to set up some NSSocketPort's manually, and
provide them to the NSConnection. For example, you would create your
server using NSSocketPort's initWithTCPPort: initializer, and then
connect another socket port to it using NSSocketPort's
initRemoteWithTCPPort:host: method.
To construct your server NSConnection, simply use NSConnection's
initWithReceivePort:sendPort: initializer, passing the server socket
port as both the send & receive port. For your client NSConnection,
use the same method, but pass nil for the receive port, and your client
socket port as the send port.
Although the documentation states that you can't retrieve the root
object from a remote connection if you provide the same send and
receive port for the local connection, I'm pretty sure [from my recent
experience] that this is not true. Presumably it's considered better
design not to, or something, but it certainly works in practice. From
what I've seen NSConnection knows to use the same socket port for
communication anyway, rather than open another one, so the point is
pretty mute either way. The DO system has lots of rules it doesn't
follow, it seems.
Anyway, I hope that helps. I can provide some sample code if you like.
It's not directly related to your question, but you may be interested
in a project I'm working on - Secure Distributed Objects - which
provides a subclass of NSPort similar to NSSocketPort, except that it
adds SSL. Since security is becoming more and more important for chat
programs, especially corporate ones, you might find it useful. You can
find it at <
http://www.sourceforge.net/projects/securedo/>, although
the version that's currently posted there doesn't work. I have got it
working, just tonight in fact, but there's still some issues with it.
I can send you the current working [but incomplete] version if you like
- just ask me off list.
Wade Tregaskis
-- Sed quis custodiet ipsos custodes?
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.