Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: TCP example

This adds an example to the documentation for the tcp module.

Index: Doc/Zsh/mod_tcp.yo
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/mod_tcp.yo,v
retrieving revision 1.1
diff -u -r1.1 mod_tcp.yo
--- Doc/Zsh/mod_tcp.yo	10 Sep 2001 21:33:16 -0000	1.1
+++ Doc/Zsh/mod_tcp.yo	21 May 2002 11:51:55 -0000
@@ -95,3 +95,35 @@
 In order to elicit more verbose output, use tt(-v).
+cindex(TCP, example)
+Here is how to create a TCP connection between two instances of zsh.  We
+need to pick an unassigned port; here we use the randomly chosen 5123.
+On tt(host1),
+example(zmodload zsh/net/tcp
+ztcp -l 5123
+ztcp -a $listenfd
+The second from last command blocks until there is an incoming connection.
+Now create a connection from tt(host2) (which may, of course, be the same
+example(zmodload zsh/net/tcp
+ztcp host1 5123
+Now on each host, tt($fd) contains a file descriptor for talking to the
+other.  For example, on tt(host1):
+example(print This is a message >&$fd)
+and on tt(host2):
+example(read -r line <&$fd; print -r - $line)
+prints `tt(This is a message)'.
+To tidy up, on tt(host1):
+example(ztcp -c $listenfd
+ztcp -c $fd)
+and on tt(host2)
+example(ztcp -c $fd)

Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 392070

The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
If you received this in error, please contact the sender and 
delete the material from any computer.

Messages sorted by: Reverse Date, Date, Thread, Author