Born Sleepy - Sam Deane's blog

  • about
  • code
  • music
  • contact
  • elegant chaos
Home › Blogs › Sam Deane's blog

Using NSSocketPort with AF_UNIX for on demand IPC

Sam Deane — Thu, 2011-12-22 19:05

In my recent post on OS X Helper Applications, I provided some sample code for installing and launching a helper application.

The host application and the helper communicated using distributed objects (NSConnection), running over mach ports (NSMachPort).

At the time, I was aware of the advice in Apple Tech Note 2083: Daemons and Agents which recommends against using mach ports, but I wanted to get something up and running, and the NSMachPort method was the one that seemed to be best documented.

However, after a lot of searching around and poring over some very sparse documentation, I've now got a version of the code working using NSSocketPort with unix domain sockets (AF_UNIX style sockets), which the tech note recommends as a good way to do IPC.

Tracking down all the details for this proved to be pretty hard work, and I had to glean various bits of information from a lot of disparate sources - tech notes, email threads and sample code.

The tough bits included: - getting NSSocketPort to use unix domain sockets - then getting NSConnection to work with them - getting launchd to launch a task on-demand when a unix domain socket is hit - getting the actual socket out of launchd in the server task

I've now updated my sample code to include all this good stuff - hopefully it will help someone else out in the future.

As a result of this the sample is a tiny bit more complex, and I've also taken the opportunity to refactor some stuff into utility classes. Because these are pretty useful I've pulled in my ECFoundation framework, and located some of them in there. However, the sample still doesn't need the vast majority of ECFoundation, so I haven't linked to the framework, I've just pulled in the source files that I need.

Check out the github repo for more details.

  • 206 reads

Login

login or register

Navigation

  • Search
  • Recent posts

Recent Tweets

Recent Tunes

Recent Posts

  • Using NSSocketPort with AF_UNIX for on demand IPC
  • OS X Code Injection
  • New Domain
  • OS X Helper Applications
  • Adding missing framework methods at runtime
  • Radar: Why Closed Bug Reporting Sucks
  • Signing nested app bundles
  • ECLogging - Better Logging For Objective-C
  • Lazy Properties Dynamic Implementation
  • Lazy Properties Revisited (Again)
more

Links

  • Sam Deane's CV
  • Sam Deane on Facebook
  • Sam Deane on MySpace
  • Sam Deane In The Real World
  • Rangers Till I Die
  • UK Mac Developers Group
  • Mountain River Tai Chi Chuan
  • National Secular Society
  • Halflight Music
  • Alien Jones
  • Keith Deane Gardening

Who's online

There are currently 0 users and 2 guests online.

Syndicate content

  • about
  • code
  • music
  • contact
  • elegant chaos