December 2000
Intermediate to advanced
784 pages
20h 54m
English
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: ...Read now
Unlock full access