.. zsh-module-meta::
   :name: zsh/net/socket
   :summary: Manipulation of Unix domain sockets

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

.. index:: single: zsocket; Function

.. index:: single: sockets; Command

.. index:: single: sockets, Unix domain; Command

``zsocket`` [ ``-alstv`` ] [ ``-d`` :var:`fd` ] [ :var:`args` ]
    
    ``zsocket`` is implemented as a builtin to allow full use of shell
    command line editing, file I/O, and job control mechanisms.
    

Outbound Connections
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. index:: single: sockets, outbound Unix domain; Command

``zsocket`` [ ``-v`` ] [ ``-d`` :var:`fd` ] :var:`filename`
    
    Open a new Unix domain connection to :var:`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:
    
    
    .. code-block:: zsh
       :class: example

        exec {REPLY}>&-
    
    
    The ``zsocket -s :var:`fd``\` command may also be used to shut down a
    socket fd before closing it. This will send an EOF to the other side,
    while this side can still read their subsequent response before closing
    the connection fully, for example.
    

Inbound Connections
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. index:: single: sockets, inbound Unix domain; Command

``zsocket`` ``-l`` [ ``-v`` ] [ ``-d`` :var:`fd` ] :var:`filename`
    
    ``zsocket -l`` will open a socket listening on :var:`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`` :var:`targetfd` ] :var:`listenfd`
    
    ``zsocket -a`` will accept an incoming connection
    to the socket associated with :var:`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``.
    

