Communication

Contents

  1. Advanced i/o, Networking, and Arithmetic Compression classlib
  2. Relaying TCP packets
  3. HTTP Virtual File System [a separate document]
  4. Uni-, Bi-, and TCP pipes as regular files
  5. Writing agents in sh: conversing through a pipe
  6. TCPStream - a C++ standard iostream over a TCP channel
  7. tcp-transactor-- a shell tool
  8. Speaking HTTP: A File-Uploader Tool,
    USENIX ;login: -- vol. 25, No. 2 -- April 2000, pp. 6-14. [on a separate site]
  9. Pushing Weather Products via an HTTP pipe [on a separate site]
  10. Metcast Push Channels: a publish-search-subscribe system for things [in a separate document on another site]
  11. Remote "command prompt" (rsh, pseudo-telnet) over HTTP [a separate document]
  12. A network (UDP) transport for TLT30G
  13. The Web IS a computer, HTML its language (and a pushy Scheme CGI setting it off)
  14. get-url and web agents in Scheme [a separate document]
  15. Streams
  16. Persistent delimited continuations for CGI programming with nested transactions
 

Relaying TCP packets

  A simple code for relaying TCP packets. One can use it as an illustration of asynchronous I/O on a TCP channel. The code also sports a finite state machine, which does the actual stream pumping and handles related errors and special conditions. The program contains a set of classes to open active/passive TCP connections, do straight/reverse DNS and other networking chores. The code has many comments.
Platforms
  Sun/Solaris 2.4, HP-UX B.10.10, g++ v2.7.2
Version
 The current version is 1.3, April 1995.
References
  Complete source code archive off this site [.shar.gz, 8K]

Other references
 
Handling multiple TCP Connections in C++
C/C++ Users Journal, v.14, No. 5, May 1996, pp. 17-23.
The article described the TCP API class library contained in the present tcp_relay code in much more detail.
comp.sources.misc
vol 47, issue 103
"Async relaying of TCP packets by a Finite Automaton [small example]" [plain text file]
The USENET article posted on comp.lang.c++ on Wed Feb 1 09:11:48 CST 1995

 

Advanced i/o, Networking, and Arithmetic Compression classlib

  A set of classes (C++ streams) that perform:
  • a variable-bit coding of sequences of integers (including Arithmetic compression ),
  • a trick of sharing a stream buffer (a "file") among several streams,
  • handling of extended file names, e.g.,
    EndianOut stream("| compress > /tmp/aa.Z");
    FILE * fp = fopen("tcp://localhost:7","r");
    fstream fp("| cat | cat",ios::in|ios::out);
    This function is also available separately, see below
  • explicit endian specification in dealing with integer streams
  • TCP streams
  • TCP transactor, a shell RPC-like tool
  • a primitive Logging service
  • a Vocabulary package, (poly/homo)morphic dictionaries with a dynamic "inheritance" path, an embedded OO system

There are also a few convenience functions/classes. The code is written in a portable way and rather commented; verification tests are provided as well.

Platforms
  i686/FreeBSD 4.9, gcc 3.2
i686/Linux 2.4.21, gcc 3.2.3 (and, reportedly, Fedora Core 2 with gcc 3.3.3 and 3.4.0)
i686/FreeBSD 4.0, gcc 2.95.2
various commercial UNIX flavors (Sun/Solaris 2.6, HP-UX B.10.10) with gcc 2.95.2
Mac and PowerMac: CodeWarrior 11
Win95/WinNT: Visual C++ 6.0
BEOS R4b4
License Type
 Public Domain
Version
 The current version is 2.7, June 26, 2005.
References
 

The README file [plain text file]

Complete source code archive [.tar.gz, 77K]

Layered I/O statement

Opening of extended file names

TCPStream - a C++ standard iostream over a TCP channel

 

Writing agents in sh: conversing through a pipe

  exec_with_piped is a tool that turns any UNIX-interactive application into a server, which runs as a single background process accepting sequences of commands from a number of clients (applications or scripts). One example of a UNIX-interactive application is telnet: this makes it possible to script remote daemons.

Executing a shell command feeding from a named FIFO pipe is trivial, except for one pitfall, as an article "Scripting daemons through pipes; e.g.: newsreader in sh? (yes!)" explains. The article also shows off a few sh-agents talking (and talking back) to daemons and other UNIX-interactive programs.

Version
 The current version is 1.4, Nov 14, 1997.
References
  pipe_scripting.shar [10K]
that contains
  • exec_with_piped.c, the scripting tool itself
  • nntp_scripting.sh, a shell news agent -- an example of using exec_with_piped to script a remote NNTP daemon (accessed via telnet)
"Scripting daemons through pipes; e.g.: newsreader in sh? (yes!)" [plain text file]
a USENET article explaining the technique, posted on comp.unix.programmer, comp.unix.admin, comp.unix.internals, comp.unix.shell newsgroups on Jan 24, 1996.

"The most primitive and nearly universal database interface",
exec_with_piped as a database "bridge" that lets applications or scripts access an SQL server without ODBC drivers, Embedded SQL, etc.

 

TCPStream - a C++ standard iostream over a TCP channel

  TCPStream is a standard C++ stream to push data to and take data from a TCP connection. A TCPStream assumes a half-duplex mode, so to speak. This is the mode in which all transaction- or request-reply- oriented TCP protocols -- HTTP, SMTP, POP, NNTP, RPC over TCP, to name just very few -- operate. This mode implies that reads and writes from/to a channel can share the same buffer. A "get" operation tacitly flushes all the data deposited by prior "put" operations. Similarly a "put" operation discards all the previously read but not yet consumed data.

The functionality of TCPStreams is identical to that of an fstream: the only difference is that it may take really a while for an i/o operation on a TCP channel to finish. It is unreasonable to make the whole application wait. Thus an application is given a chance to tell a TCP buffer being created that it does not want the network i/o to block. Application does it by deriving and instantiating a NetCallback object. If the currently registered NetCallback::async_io_hint() returns true, a newly created TCP socket is turned into a (POSIX) non-blocking mode; when the stream wants to flush/fill its buffer and the operation can't be completed immediately, the stream calls NetCallback::yield(). When this function returns, the stream gives another try to the input/output operation.

With the TCPStream, you can check your POP3 mail like this:

   TCPstream link;
   link.connect(SocketAddr("hostname",110));
   if( !link.is_open() || !link )
      _error("Failed to establish the connection");
   link << "USER " << user_name << endl;
   int resp_code; char buffer[100];
   link >> resp_code;
   if( ! link.get(buffer,sizeof(buffer)-1,'\r').good() )
      _error("error reading a response line from the link");
   if( resp_code >= 300 )
      _error("bummer");
   ...etc...
See a validation code file vTCPstream.cc for more examples.

TCP streams are helpful on a server side as well. See vTCPstream_server.cc for a sample (forking) server.

Version
 The current version is 2.6, November 19, 2000.
References
 

Advanced i/o and Arithmetic Compression classlib
the package that contains the TCPStream class and its implementation

HTTP Virtual File System
one project that made use of the TCPStream class

 

tcp-transactor-- a shell tool

  This code is a scripting tool to talk to any TCP server: an HTTP daemon, a finger daemon, or any other RPC-like service. The tool brings benefits of the TCPStream class to a command line, sh or other scripts.

This code is to perform a single transaction -- a request/reply exchange -- with a "server" on the other end of a TCP pipe. The tool establishes a connection to a server, sends a request, listens to the reply, and prints it on its standard output.

Examples:

     tcp-trans localhost:79 user-name
will emulate finger

     tcp-trans proxyhost:80 "GET http://some.host/ HTTP/1.1"
         "Host: some.host:80" "User-Agent: $LOGNAME" ""

will fetch the root web page off some.host using a web proxy

     tcp-trans some.host:25 "expn <postmaster>" "quit"
reveals the real person behind the postmaster

     tcp-trans some.host:13
prints the current timestamp off the some.host
 

Platforms
  various flavors of UNIX (Sun/Solaris 2.6, HP-UX B.10.xx), FreeBSD 4.0, Linux 2.2.xx, Win9x/WinNT, BeOS
Version
 The current version is 1.2, January 4, 2000.
References
 

source code archive off this site [.cc, 4K]

Requires
TCPStream - a C++ standard iostream over a TCP channel

 

A network (UDP) transport for TLT30G

 

This is a source code archive that accompanies a DDJ article "Distributing Data Using TLT30G". TLT30G is a software system for distributing files from a central location to a number of clients over unidirectional, noisy, and generally slow communication links. The code archive is a self-contained implementation of a particular transport layer of the TLT30G broadcasting system. This Link Access Plugin implements transmission of TLT30G's segments as UDP datagrams over a TCP/IP network. Of all the protocols of the TCP/IP suite, UDP fits best for a packet-oriented broadcast without any feedback.

The code in the archive below defines and implements basic network classes (IPaddress, SocketAddr), UDP classes (UDPsocket, UDPsocketIn, UDPsocketOut), datagram streams to assemble and disassemble a UDP datagram, and the TLT30G's LAP interface itself.
 

Platforms
  Sun/Solaris 2.4, HP-UX B.10.10, g++ v2.7.2
Version
 The current version is 1.2, August 1996.
References
  LAPNet source code archive off this site [.tar.gz, 12K]

Other references
 
Distributing Data Using TLT30G
Dr.Dobb's Journal, #289, September 1998, pp.34-40, 92-93.
Speaking in Iostreams-ese
C/C++ Users Journal, v.15, No. 5, May 1997, pp. 47-55.

 

The Web IS a computer, HTML its language (and a pushy Scheme CGI setting it off)

  An article that shows off a tail-f CGI script that starts a Server-Net-Browser hyper-computer. The article argues that the Web itself may act as some sort of a distributed, multi-threaded hyper-computer.

Keywords: Finite Automaton, FSM, HTTP, Scheme, CGI, Computation, WWW, Push

Version
 The current version is 2.0, Mar 21, 1997.
References
 

tail-f.scm script's description

A USENET article explaining the technique [plain text file],
posted on comp.lang.scheme, comp.programming, comp.infosystems.www.authoring.cgi, comp.infosystems.www.misc newsgroups on Tue Mar 25 13:17:13 CST 1997.

 


Last updated May 4, 2008

This site's top page is http://okmij.org/ftp/

oleg-at-okmij.org
Your comments, problem reports, questions are very welcome!