Skip to content

Instantly share code, notes, and snippets.

@tony-o
Created May 30, 2014 21:45
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 tony-o/b11e87e582d56b1a1979 to your computer and use it in GitHub Desktop.
Save tony-o/b11e87e582d56b1a1979 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl6
class REST::Server {
has $.host = '127.0.0.1';
has $.port = 8080;
has %.options is rw;
has $.debug = 1;
has Supply $!scheduler;
method listen() {
$!scheduler = IO::Socket::Async.listen(
$.host,
$.port,
);
my $num = 0;
$!scheduler.tap(sub ($connection) {
my $snum = $num++;
"accepted connection $snum".say if $.debug;
$connection.send("HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 6\r\n\r\nstring");
"closing connection $snum".say if $.debug;
$connection.close;
});
sleep 50;
}
};
my $s = REST::Server.new;
$s.listen;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment