Skip to content

Instantly share code, notes, and snippets.

@jberger
Last active February 9, 2018 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jberger/91e39455f77a077baa2e30f4b51d2ca5 to your computer and use it in GitHub Desktop.
Save jberger/91e39455f77a077baa2e30f4b51d2ca5 to your computer and use it in GitHub Desktop.
RFC865 compliant QOTD server using Mojo::IOLoop. See also https://tools.ietf.org/html/rfc865
#!/usr/bin/env perl
use Mojo::IOLoop;
my $server = Mojo::IOLoop->server({address => '127.0.0.1', port => 17}, sub {
my ($loop, $stream, $id) = @_;
$loop->subprocess(sub{ scalar `fortune -n 512 -s` }, sub {
my (undef, $err, $qotd) = @_;
$stream->write($qotd, sub { shift->close });
});
});
Mojo::IOLoop->acceptor($server);
Mojo::IOLoop->start;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment