IBM Research

Decaffienated TCP

Created: 14.7.97
Modified: 10.9.97
Contents:
  1. Synopsis
  2. Description

1. Synopsis

non-AIX:
	decaf port program arguments

AIX:
	: bsh or ksh
	# inline decaffienation

	finish () {
		# your handler here
		}

	read fd < /dev/tcp || finish "/dev/tcp driver error"
	echo $fd $Port > /dev/tcp || finish "$Port inaccessible"
	while :
	do
		(read afd clienthost clientport <&$fd && \
			(program arguments <&$afd >&$afd &))
		wait
	done

2. Description

Decaf simplifies the work of writing TCP servers. It creates a TCP socket, binds to the specified port, and invokes the program specified on the command line together with the arguments once for each client. The invoked program uses stdin and stdout to talk with the client. The connection is broken when the program exits.

Networking types will recognize that decaf does almost exactly what inetd is supposed to do. Decaf is therefore simply a good developmental alternative to messing with /etc/services. If you're on AIX4.x and can install the TCP driver, use the script instead: it's equally efficient, but more robust, and is a more detailed source reference anyway. Given the inetd and the inline alternatives, I don't feel compelled at the moment to incorporate the proper waiting behavior into decaf. If you do, please yell.


Version history

1.0 14.7.97 First cut server. Does not do wait().

[ Research home page | IBM home page | Search | ContactIBM | Legal | Author ]