22.25 The zsh/net/socket Module

The zsh/net/socket module makes available one builtin command:

zsocket [ -altv ] [ -d fd ] [ args ]

zsocket is implemented as a builtin to allow full use of shell command line editing, file I/O, and job control mechanisms.

22.25.1 Outbound Connections

zsocket [ -v ] [ -d fd ] filename

Open a new Unix domain connection to filename. The shell parameter REPLY will be set to the file descriptor associated with that connection. Currently, only stream connections are supported.

If -d is specified, its argument will be taken as the target file descriptor for the connection.

In order to elicit more verbose output, use -v.

File descriptors can be closed with normal shell syntax when no longer needed, for example:

exec {REPLY}>&-

22.25.2 Inbound Connections

zsocket -l [ -v ] [ -d fd ] filename

zsocket -l will open a socket listening on filename. The shell parameter REPLY will be set to the file descriptor associated with that listener. The file descriptor remains open in subshells and forked external executables.

If -d is specified, its argument will be taken as the target file descriptor for the connection.

In order to elicit more verbose output, use -v.

zsocket -a [ -tv ] [ -d targetfd ] listenfd

zsocket -a will accept an incoming connection to the socket associated with listenfd. The shell parameter REPLY will be set to the file descriptor associated with the inbound connection. The file descriptor remains open in subshells and forked external executables.

If -d is specified, its argument will be taken as the target file descriptor for the connection.

If -t is specified, zsocket will return if no incoming connection is pending. Otherwise it will wait for one.

In order to elicit more verbose output, use -v.