[launchd-dev] UNIX SOCKET problem

Quinn "The Eskimo!" eskimo1 at apple.com
Tue Sep 27 02:30:49 PDT 2011


On 26 Sep 2011, at 12:18, Gian Luca Gaiba wrote:

> I didn't set any port... 
> when I set up a Inet socket I configure a port
> but in UNIX sock I don't know where to set a port...

UNIX domain sockets don't need a port.  In a TCP connection, the destination address consists of the IP address (the machine on which the server is running) and a port (to identify the service within that machine).  For a UNIX domain socket the server is always running on the local machine, so you only need to identify the service on the machine, which is what the path does.

As to your original problem, I'm not sure what's going on.  The best solution to this problem is to have launchd managing your listening socket for you.  I don't know of a simple sample that shows this for UNIX domain sockets, but the SampleD sample code shows it for TCP sockets.

<http://developer.apple.com/library/mac/#samplecode/SampleD/>

You can also look at BetterAuthorizationSample, which is rather complex but does show the UNIX domain sockets side of things.

<http://developer.apple.com/library/mac/#samplecode/BetterAuthorizationSample/>

If you must create your own UNIX domain socket (which, again, isn't what I recommend), you can look at the CFLocalServer sample code, which shows how to do that.

<http://developer.apple.com/library/mac/samplecode/CFLocalServer/>

S+E
--
Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware




More information about the launchd-dev mailing list