Hello,
I need to have a high performance communication between 2 applications. I tried AppleEvent but it is not really a good option. I thought to use a named pipe but I do not know how to use them in COCOA.
Thanks in advance for your help :)
Hello,
I need to have a high performance communication between 2 applications. I tried AppleEvent but it is not really a good option. I thought to use a named pipe but I do not know how to use them in COCOA.
Thanks in advance for your help :)
There's no special way to do it in Cocoa. You'd basically make the fifo and once you had that, your process could then read it/write it using the standard Cocoa wrappers like NSFileHandle. You could check for its existence with NSFileManager or whatever, but you'd still have to call mkfifo(2) at some point to create the named pipe.
So:
if( mkfifo("/tmp/my_named_pipe", 0644) == -1 ) {
// some error handling
abort();
}
// Open and use the fifo as you would any file in Cocoa, but remember that it's a FIFO
NSFileHandle* fifoIN = [NSFileHandle fileForReadingAtPath:@"/tmp/my_named_pipe"];
Personally, I would recommend using either a BSD or Unix socket instead. There's lots of Framework support for sockets, sometimes a bi-directional channel is more useful as well, and you wouldn't have to worry about whether the reader or the writer is ready first.
There are alternatives to named pipes: