Using the inetd Super Daemon

Let's go back to Figure 10.3 and take a second look at the interact() function:

sub interact {
  my $sock = shift;
  STDIN->fdopen($sock,"<")  or die "Can't reopen STDIN: $!";
  STDOUT->fdopen($sock,">") or die "Can't reopen STDOUT: $!";
  STDERR->fdopen($sock,">") or die "Can't reopen STDERR: $!";
  $|=1;
  my $bot = Chatbot::Eliza->new;
  $bot->command_interface();
}

The psychotherapist daemon is pretty generic in its handling of incoming connections and forking. In fact, interact() is the only place where application-specific code appears.

Now consider this version of interact():

 sub interact { my $sock = shift; STDIN->fdopen($sock,"<") or die "Can't reopen STDIN: $!"; STDOUT->fdopen($sock,">") or die "Can't reopen STDOUT: ...

Get Network Programming with Perl now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.