A Unix domain socket "or IPC (inter-process communication) socket is a data communications endpoint for exchanging data between processes executing within the same host operating system."
The Squeak/Pharo VM's socket plugin has had support for Unix domain sockets, as per SocketPrims.pdf, written by Ian Piumarta, dated 2007, "The old API assumes 32-bit INET4 (host) addresses and numbered service (port) addresses throughought. The new API supports arbitray host address sizes and both numbered and symbolic host and service names. [...] SQ_SOCKET_FAMILY_LOCAL The lookup should only find local (some- times called "Unix") domain host addresses. In this case, the host name should be empty and the service name should be a path to a node in the filesystem associated with a named socket."
And in code, platforms/unix/plugins/SocketPlugin/sqUnixSocket.c:
On the Smalltalk side, the Socket class has no support though. The key part is in the following fragment in "Socket>>initialize":
Socket>>primSocketCreateNetwork:type:receiveBufferSize:sendBufSize:semdIndex: comments, "Return a new socket handle for a socket of the given type and buffer sizes. Return nil if socket creation fails. The netType parameter is platform dependent and can be used to encode both the protocol type (IP, Xerox XNS, etc.) and/or the physical network interface to use if this host is connected to multiple networks. A zero netType means to use IP protocols and the primary (or only) network interface."
Meaning, this bit "primSocketCreateNetwork: 0" hardcodes the use of TCP/IP. Easy enough to fix; let's rename Socket>>initialize to Socket>>initialize:withDomain:, changing the key part:
Change Socket>>initialize to preserve the default behaviour:
Next, create Socket class>>newIPC like this:
Here "TCPSocketType" really means SOCK_STREAM in the Unix C API parlance.
We'll need Socket>>connectTo: as well:
Now, how to get a Unix domain socket address? After some experimentation, this works:
To test, use some known-working Unix domain socket test programs. The following is a slightly modified, rather self-explanatory Python server from here:
There is a corresponding client program. Run the two to verify that the server works.
Back to Smalltalk, the following code run in a workspace will connect to above Python server, send, receive, then print "Hello, from Smalltalk!" on the transcript. Tested on OSX and Linux with Pharo 2.0.