---
name: "unix_sockets"
section: "3tcl"
platform: "linux"
package: "tcl-unix-sockets"
version: "0.5-3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/unix_sockets"
---

# unix\_sockets(3tcl)

Communicate using unix domain sockets

```

```

## 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)](/close/n.md), [chan(n)](/chan/n.md), [socket(n)](/socket/n.md), [read(n)](/read/n.md), [puts(n)](/puts/n.md), [eof(n)](/eof/n.md), [fblocked(n)](/fblocked/n.md), [flush(n)](/flush/n.md)

## KEYWORDS

socket, channel, unix, ipc
