oracular (3) unix_sockets.3tcl.gz

NAME
unix_sockets - Communicate using unix domain sockets
SYNOPSIS
unix_sockets::listen path accept_handler unix_sockets::connect path
DESCRIPTION
Unix domain sockets are a filesystem based IPC mechanism similar to IP sockets, except that they can only be used by processes on the same system. This package provides a wrapper to use them from Tcl scripts. unix_sockets::listen path accept_handler Open a listening socket with the path path. If path already exists, it is unlinked first. You must have permission to create path in it's parent directory. When a client connects to the listening socket, accept_handler is invoked with the channel handle of the new client connection appended. unix_sockets::connect path Connect as a client to the unix domain socket path. The channel handle for the new socket is returned.
EXAMPLE
A simple server that echos back to the client the first line it sends, then closes the socket: proc readable {con} { set msg [gets $con] puts $con $msg close $con } proc accept {con} { chan event $con readable [list readable $con] } set listen [unix_sockets::listen /tmp/example.socket accept] vwait ::forever A client that opens a socket, writes a line to it, waits for a response and exits: proc readable {con} { set msg [gets $con] puts "got response: ($msg)" set ::done 1 } set con [unix_sockets::connect /tmp/example.socket] puts $con "hello, world" flush $con chan event $con readable [list readable $con] vwait ::done
SEE ALSO
close(n), chan(n), socket(n), read(n), puts(n), eof(n), fblocked(n), flush(n)
KEYWORDS
socket, channel, unix, ipc