unix_sockets - Communicate using unix domain sockets
Contents
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::listenpathaccept_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::connectpath
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:
procreadable{con}{setmsg[gets$con]puts$con$msgclose$con}procaccept{con}{chanevent$conreadable[listreadable$con]}setlisten[unix_sockets::listen/tmp/example.socketaccept]vwait::forever
A client that opens a socket, writes a line to it, waits for a response and exits:
procreadable{con}{setmsg[gets$con]puts"gotresponse:($msg)"set::done1}setcon[unix_sockets::connect/tmp/example.socket]puts$con"hello,world"flush$conchanevent$conreadable[listreadable$con]vwait::doneKeywords
socket, channel, unix, ipc
Tcl-Extensions 0.1 unix_sockets(3tcl)
Name
unix_sockets - Communicate using unix domain sockets
See Also
close(n), chan(n), socket(n), read(n), puts(n), eof(n), fblocked(n), flush(n)
Synopsis
unix_sockets::listenpathaccept_handlerunix_sockets::connectpath
