On Unix, you can create a unix domain socket with std.socket similar to a TCP socket, but only locally. Here is a sample code:
// SERVER import std.socket; void main() { auto listener = new Socket(AddressFamily.UNIX, SocketType.STREAM); listener.bind(new UnixAddress("/home/me/uds")); listener.listen(10); /*while(1)*/ { auto soc = listener.accept(); soc.send("cool\n"); soc.close(); } listener.close(); import core.sys.posix.unistd; unlink("/home/me/uds"); }
And the client:
void main() { auto soc = new Socket(AddressFamily.UNIX, SocketType.STREAM); soc.connect(new UnixAddress("/home/me/uds")); import std.stdio; char[1222] buf; writeln(buf[0 .. soc.receive(buf)]); soc.close(); }
The only thing they need to know about each other is what the messages mean (of course), and the file system path to the socket.
Unix also runs named pipes, but they are not bidirectional, like a unix domain socket (or Windows named pipe)
If you need a Jewish unix channel, they are called FIFO files and are executed using the mkfifo API function. You can access it using import core.sys.posix.sys.stat; and then use it the same way as in C: pass the line and mode to it to create the file, do not forget to check the return value, then read / write it using regular Unix file functions, for example read , write , close , everything from import core.sys.posix.unistd; . See the C documentation for these functions, for example. man 2 read or man 3 mkfifo if you are on Linux, or just do an online search for these pages.
But I think the unix domain socket is what you are looking for, and it works basically the same as any other socket, as shown in my example above.
Windows does things differently, and the standard D library does not even include prototypes of OS API functions.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365150%28v=vs.85%29.aspx
You create a named pipe with this function, giving it a path name that other processes can use (similar to the Unix socket domain, but not in a unified file system). Then you use the CreateFile function to open this channel, and later you can talk to it, like to any other file.
There are two ways to get function prototypes so that you can call these functions from D. One of them is to copy / paste them yourself, for example:
extern(Windows) HANDLE CreateNamedPipeA( LPCTSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode, DWORD nMaxInstances, DWORD nOutBufferSize, DWORD nInBufferSize, DWORD nDefaultTimeOut, LPSECURITY_ATTRIBUTES lpSecurityAttributes );
Firstly, import core.sys.windows.windows; to get basic definitions like Windows, and then just add ticks like this to the file. This is the same as MSDN, only with things like βDeletedβ. (you could just change them only to the D in keyword).
The big thing is adding A or W to the name. This is mentioned at the bottom of the Microsoft documentation on Unicode and ANSI. Variants A take ascii strings. Version W accepts utf-16, wstring in D. Version W is recommended, but in some cases version A is a little easier to use.
Or you can download ready-made win32 bindings from here: https://github.com/AndrejMitrovic/DWinProgramming/tree/master/WindowsAPI and use them when creating.
If you just need a couple of functions, I prefer to copy / paste to avoid dependency, but if you work a lot with the Windows API, download the full bindings.
I wrote a cross-platform terminal emulator in D that uses these methods: https://github.com/adamdruppe/terminal-emulator
The detachable part uses the unix domain socket server: https://github.com/adamdruppe/terminal-emulator/blob/master/detachable.d
The attachment is a UDS client https://github.com/adamdruppe/terminal-emulator/blob/master/attach.d
The kernel of the Windows emulator uses a specialized named pipe to create its own asynchronous "anonymous" pipe, and not for your use, but shows how you can call the functions: https://github.com/adamdruppe/terminal-emulator/blob/master/terminalemulator. d
Shared memory is another thing you can do, but expect a little help from the D library, you'll have to use the OS features. But itβs not difficult, at least function prototypes exist in Unix: import core.sys.posix.sys.shm and use the same functions as in C.
I never did this on Windows, but a quick search says that yo can just create a memory mapped file: http://msdn.microsoft.com/en-us/library/windows/desktop/aa366551%28v=vs.85 % 29.aspx
which maybe, maybe, can get help from phobos: http://dlang.org/phobos/std_mmfile.html , but then again, I never tried this. When I need shared memory, I just made shmget functions, etc. Unix (this was in my simpledisplay.d https://github.com/adamdruppe/arsd/blob/master/simpledisplay.d , which uses it to communicate with the X server).
The bottom line, however, is Unix domain sockets, basically the same as TCP sockets, and phobos's std.socket support.
Everything else is done the same way as in C.