John, thanks a lot!
> 1) What is the type of "pipe"? It looks like it is an NSFileHandle, not an NSPipe. Don't call it a pipe if it isn't.
Well I thought a “fifo” (the thing created by the mkfifo service) was a “named pipe” years before NSPipe has been ever designed. Anyway, whatever the proper name is, this is the API I tried to use 🙂
Correct me please if I am wrong, but I don't know how would I use NSPipe to communicate betwixt a server a client; my understanding was they serve in different cases (e.g., to pipe a standard output from a process I have launched programmatically). As always, I might be missing something.
How would I “just use pipes” (re your comment No 5) in this case? Can you please point me to some code sample somewhere?
> 2) You are opening a file handle for writing at a path, then attempting to create a MKFO at that path
I am not; check please the line 03. The path I am opening a writing handle is the path of the server {fifo, named pipe, whatever you want to call the thing}. Then, I append the PID of the client to the end of the path to get a unique name, and create another {fifo...} for the client in there.
> 3) You wouldn't know if mkfifo failed because you aren't checking result codes
Of course I am. In the real code, there's lots of logs, error checking etc., which I have naturally removed so that the code presented is concise and intelligible, without obscuring boilerplate. That's why I have added the comment that it never fails, for it does not.
> 4) Why is the client creating the FIFO anyway?
To gen answers from the server. The communication is duplex; first the client sends a request to the server (through its {fifo...} using the local "pipe" file handle, created at the line 02 — this works perfectly.
Part of the request is the path to the client {fifo...}, created at the line 04; the server is presumed to write its reponse to there, and the client would read it. Alas this part does not work, for the creation of the read handle for this {fifo...} hangs.
> 6) There are lots more ways to communicate than FIFOs
Absolutely; my first choice were Distributed Objects, which are ways more convenient. Alas, they do not work for me, see please the link at the bottom of my original message.
While I could e.g., establish a socket-level communication, it is darn complex for such a simple task. I considered the {fifos...} about the 2nd easiest after DOs. Might, of course, be missing something.
> 7) Never use NSFileHandle
What?!? :-O I am using the thing for 20-odd years without much problems, and so far I believed they are the first option for most streams in Cocoa. After all, the aforementioned NSPipe is filehandle-based; so is NSTask etc.?!?
> 8) I'm not sure about what architecture you are targeting here. While macOS supports many different schools of client/server talk, you shouldn't mix schools. Pick one paradigm and stay with it. Maybe don't pick one from the 1970s
Well in my experience, technologies of '70s tend to work pretty well; often much better than today's ones. Anyway those {fifos...} were not my first option, but as written above, alas, there's a weird problem with Distributed Objects, which always are the first option for all server/client communication. 10.8+ there's XPC, but since I target a Mac OS X 10.6 Server, that would not help much. While I could use sockets of low-level Mach APIs, I would rather keep high-level for my task, which is (should be) pretty simple and not too demanding as for efficiency.
Thanks again,
OC