Date: Wed, 26 Sep 2007 09:48:02 +0100
From: Peter Stephenson <pws@xxxxxxx>
To: zsh-users@xxxxxxxxxx
Subject: Re: zsocket help
"S. Cowles" wrote:
does anyone have a piece of sample code showing practical usage of
zsockets? i'm not having success developing functioning zsocket code
using a current zsh cvs code pull. i've been working from the zshall man
page and from the partial zsocket examples from zshlovers without success.
any help would be appreciated. thanks.
I got the following to work.
In terminal A:
% typeset REPLY
% zmodload zsh/net/socket
% zsocket -l /tmp/zsocket
% print $REPLY
11
% zsocket -a 11
This now blocks. (I put the "typeset REPLY" at the start to ensure REPLY is
created as a string, as you would naturally do in a function.)
In terminal B:
% typeset REPLY
% zmodload zsh/net/socket
% zsocket /tmp/zsocket
% print $REPLY
3
Terminal A returns at this point and I did:
% print $REPLY
3
% read -u3 && print $REPLY
and in terminal B:
% print -u3 This is a message on the socket
which produces in terminal A:
This is a message on the socket
As far as I can see there's no way of closing the file descriptors using
zsocket, which seems an omission. Presumably you can use "exec 3>&-"
etc. although to close a file descriptor over 9 you need to do something
like:
% fd=11
% exec {fd}>&-
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070