Setting both Dump_log and Input_log in the constructor of Net::Telnet
will allow us to see what is really going on on the connection.
We also add a call to wait for something that is likely won't show up
in the output. Depending on where the demo application (the daemon)
is running you might need to change the $hostname variable.
Example 10-1. examples/cli/cli_01.pl
#!/usr/bin/perl
use strict;
use warnings;
use Net::Telnet;
my $port = 8000;
my $hostname = 'localhost';
my $telnet = Net::Telnet->new(
Port => $port,
Host => $hostname,
Dump_log => 'dump.log',
Input_log => 'input.log',
);
print "opened\n";
{
my ($prematch, $match) = $telnet->waitfor('/not likely to show up/');
}
print "after wait\n";
Running the script we notice that after printing "opened" it waits
quite a lot of time and it never prints "after wait".
This happend because waitfor was waiting for a string that never
showed up. Hence it gave up waiting after the built-in timeout
period. Once it reached the timeout it called the default errmode()
function which is the "die" function. So the script never reached
the second print() and did not have a chance to print anything.
| Prev | Home (Copyright Gabor Szabo) Perl Training Israel | Next |
| Command Line Interface | Up | Reduce timeout |