Re: NSMessagePort/NSSocketPort & Distributed Objects
Re: NSMessagePort/NSSocketPort & Distributed Objects
- Subject: Re: NSMessagePort/NSSocketPort & Distributed Objects
- From: Robert Sesek <email@hidden>
- Date: Sun, 16 Sep 2007 19:45:01 -0400
A year or so ago when I was working on a Cocoa project I created a
database server (using SQLite) and then clients that connected to it
via distributed objects, which is shared over a Bonjour service. The
basic cycle is:
1. On a computer, one launches the server application which starts
sharing a Bonjour D-O services that clients can connect to
2. A user opens the client application and a list of all the
computers broadcasting the Bonjour service shows up, to one of which
the user connects
3. The D-O is shared
As I stated above, the code is a year old and isn't necessarily a
great piece of Cocoa work, but it's completely functional and it has
been deployed without issues.
You can find the code in my Git repository here:
http://www.bluestatic.org/git/?p=Tindex.git;a=tree
The files of interest to you would be:
Server/DatabaseServer.m: The server side of the D-O using NSSocketPort
Client/AppController.m: The Bonjour/discovery portion of the connection
Client/ClientController.m: The -init: method shows how to get the
proxied object
While this may not be exactly what you're looking for, it is a
functional example of D-O using NSSocketPort.
- Robert Sesek
On Sep 15, 2007, at 15:35, James Bucanek wrote:
Greetings,
I've returned, once again, to my client/daemon communications
conundrum.
I'm desperately seeking example code that successfully uses either
NSMessagePort or NSSocketPort using a local domain socket to create
an NSConnection.
If you somehow missed my hundred-odd whiny posts in the past, let
me recap: My project has several daemon and client processes that
communicate using distributed objects. Because of Mach namespace
issues, it's impossible for some processes to "see" either the
clients or daemons.
This technote (<http://developer.apple.com/technotes/tn2005/
tn2083.html>), kindly provided by Dave Camp, strongly suggests that
using Mach ports to communicate with daemons is bad. If you need
interprocess communications that gets around problems like
namespaces one should use BSD sockets. It provides some Core
Foundation example code that uses local (AF_UNIX) sockets.
"Great!" I say to myself. I'll just replace the default NSPort
stuff with either NSMessagePort or NSSockPort created from an
AF_UNIX socket and I'll be back in business. However, after over a
day of experimentation I have yet to get this to work.
I can't even remember all of the combinations that I've tried, but
in the end I get one of four results: The client can't see/connect
to the server, the client connects but hangs when it calls
[NSConnection rootProxy], the client crashes with a bad address
when it calls rootProxy, the client throws some kind of connection
exception when it calls rootProxy.
What's shocking -- and a little scary -- is that I can find
virtually NO working code examples using DO via NSMessagePort or
NSSocketPort using local sockets. A search of developer.apple.com's
example source turns up zero hits. Even a code.Google search
doesn't turn up much. I was able to find a thread on the list from
2005 titled "NSSocketPort vs. AF_UNIX" that implies that someone
got this to work, but there wasn't enough code to reproduce it.
Any pointers would be greatly appreciated.
--
James Bucanek
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden