Version 1 of Unix Domain Sockets

Updated 2010-11-28 18:29:52 by jmn

Unix Domain Sockets

Unix sockets are a commonly used IPC method on unix-based platforms.

Tcl as at 2010 doesn't seem able to directly interface with them. There are various extensions going back over a decade which claim to support them, but these are in various states of buildability and in need of modernisation to catch up with Tcl.

The rough equivalent on Windows is Named Pipes, and there, with the help of the excellent Twapi module... Tcl has access to them using standard Tcl commands like puts,read & chan.

It would be great to see Unix Socket support in the core.


jmn The inspiration for creating this page was finding a simple perl script demonstrating an interface to the Cyrus Unix sockets notification handler. It looked like this would be a great way to add some custom functionality to my mailserver. If only Tcl supported it. I had thought that perl had replaced the original Tcl scripts shipped with cyrus due to concerns such as superior IMAP libraries - but it looks like perl beats us even on basic sysadmin 'glue'.

If you think like me that this is an important feature to have available in the core - comment here and let's raise the profile of this issue a little!


As Alexandre Ferrieux pointed out on comp.lang.tcl - [open "|nc -U ..." r+] can be used to access a Unix socket.

To get Tcl code to act a server, something more complicated such as the following can be used:

  socat UNIX-RECVFROM:/var/socket/name,user=whoever,reuseaddr,fork system'/path/to/myscript.tcl',fdout=3,nofork 

where fdout=3 allows stdout to be treated normally instead of being redirected back to the client on the socket. (see socat manual http://www.dest-unreach.org/socat/ )

See also: