#!/usr/athena/bin/perl
require 'sys/socket.ph';
$thisfile = '/tmp/bar';
$thatfile = '/tmp/foo';
$this = pack("s a108", &AF_UNIX, $thisfile);
$that = pack("s a108", &AF_UNIX, $thatfile);
$SIG{'INT'} = 'dokill';

sub dokill {
    unlink $thisfile;
    kill 9,$child if $child;
}

socket(S, &AF_UNIX, &SOCK_STREAM, 0) || die $!;
print "socket ok\n";
bind(S, $this) || die $!;
print "bind ok\n";

# Call up the server.

connect(S,$that) || die $!;
print "connect ok\n";

select(S); $| = 1; select(STDOUT);

# Avoid deadlock by forking.

if($child = fork) {
    while (<STDIN>) {
	print S;
    }
    sleep 3;
    do dokill();
}
else {
    while(<S>) {
	print;
    }
}
