Skip to content
Browse files

Echo in progress, not working yet

  • Loading branch information...
1 parent 5deb3e3 commit a56d10de5a22d9dfe31b6aed0565ef08098e36b3 @sciurus committed
Showing with 42 additions and 0 deletions.
  1. +42 −0 echo/echo.pl
View
42 echo/echo.pl
@@ -0,0 +1,42 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use v5.10.0;
+
+use AnyEvent;
+use AnyEvent::Handle;
+use AnyEvent::Socket;
+
+sub echo {
+ my ( $fh, $host, $port ) = @_;
+
+ say 'accepted connection';
+
+ my $handle = AnyEvent::Handle->new(
+ fh => $fh,
+ on_error => sub {
+ my ( $handle, $fatal, $message ) = @_;
+ say "error occured, it was $message";
+ },
+ on_eof => sub {
+ my $handle = shift;
+ $handle->destroy();
+ say 'connection closed';
+ },
+ on_read => sub {
+ my $handle = shift;
+ my $buffer = $handle->{rbuf};
+ $handle->push_write($buffer);
+ $handle->{rbuf} = '';
+ say 'buffer written!';
+ },
+ );
+
+}
+
+my $guard = tcp_server( '127.0.0.1', 3000, \&echo );
+
+say 'listening on port 3000';
+
+AE::cv->recv();

0 comments on commit a56d10d

Please sign in to comment.
Something went wrong with that request. Please try again.