Contents
TCPStream
- a C++ standard iostream
over a TCP channel
get-url
and web agents in Scheme [a separate document]
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.
.shar.gz
, 8K]
TCP API class library
contained in the present tcp_relay
code in much more detail.
C++ streams
) that perform: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.
The README file [plain text file]
Complete source code
archive [.tar.gz
, 77K]
Opening of extended file names
TCPStream
- a C++ standard iostream
over a TCP channel
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.
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)
"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 channelTCPStream
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 TCPStream
s 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.
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
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
(Sun/Solaris 2.6, HP-UX B.10.xx)
, FreeBSD 4.0, Linux 2.2.xx, Win9x/WinNT, BeOS
source code archive off this site [.cc
, 4K]
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.
.tar.gz
, 12K]
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
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.
oleg-at-okmij.org