Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Simple Echo Server

The Simple Echo Server lets you telnet to it and echos back every word you type.

#!/usr/bin/perl
use strict;
use warnings;

use FindBin;
use lib "$FindBin::Bin/lib";
use SimpleEchoServer;

SimpleEchoServer->run(port => 8000);
package SimpleEchoServer;
use warnings;
use strict;

use base 'Net::Server';
my $EOL   = "\015\012";

sub process_request {
    my $self = shift;
    while( my $line = <STDIN> ) {
        $line =~ s/\r?\n$//;
        print qq(You said "$line"$EOL);
        last if $line eq "bye";
    }
}

1;