manpagez: man pages & more
info gawkinet
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.1 gawk's Networking Mechanisms

The ‘|&’ operator introduced in gawk 3.1 for use in communicating with a coprocess is described in (gawk)Two-way I/O section `Two-way Communications With Another Process' in GAWK: Effective AWK Programming. It shows how to do two-way I/O to a separate process, sending it data with print or printf and reading data with getline. If you haven't read it already, you should detour there to do so.

gawk transparently extends the two-way I/O mechanism to simple networking through the use of special file names. When a “coprocess” that matches the special files we are about to describe is started, gawk creates the appropriate network connection, and then two-way I/O proceeds as usual.

At the C, C++, and Perl level, networking is accomplished via sockets, an Application Programming Interface (API) originally developed at the University of California at Berkeley that is now used almost universally for TCP/IP networking. Socket level programming, while fairly straightforward, requires paying attention to a number of details, as well as using binary data. It is not well-suited for use from a high-level language like awk. The special files provided in gawk hide the details from the programmer, making things much simpler and easier to use.

The special file name for network access is made up of several fields, all of which are mandatory:

 
/inet/protocol/localport/hostname/remoteport

The ‘/inet/’ field is, of course, constant when accessing the network. The localport and remoteport fields do not have a meaning when used with ‘/inet/raw’ because “ports” only apply to TCP and UDP. So, when using ‘/inet/raw’, the port fields always have to be ‘0’.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]
© manpagez.com 2000-2018
Individual documents may contain additional copyright information.