Simple Echo Server


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


examples/server/simple_echo_server.pl
#!/usr/bin/perl
use strict;
use warnings;

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

SimpleEchoServer->run(port => 8000);

examples/server/lib/SimpleEchoServer.pm
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;