#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; use AnyEvent; use AnyEvent::Handle; use AnyEvent::Socket; use AnyEvent::Log; use IO::Socket::SSL; use EV; use Cpanel::JSON::XS; use Path::Tiny qw(path); $IO::Socket::SSL::DEBUG = 3; $AnyEvent::Log::FILTER->level ("trace"); my $json_obj = Cpanel::JSON::XS->new->ascii->pretty(1)->allow_nonref; my $config_file = Path::Tiny::path ("config.json"); die "Must have config file" if (!$config_file->exists); my $config_raw = $config_file->slurp (); my $config; my $ret = eval { $config = $json_obj->decode ($config_raw); }; if (!$ret) { die "Error Parsing JSON\n$@\n"; } tcp_server $config->{LocalAddr}, $config->{LocalPort}, sub { my ($fh) = @_; print "host started\n"; my $handle = new AnyEvent::Handle ( fh => $fh, tls => "accept", tls_ctx => { cert_file => $config->{cert_file}, key_file => $config->{key_file} }, on_read => sub { my ($handle) = @_; print "ON_READ :" . $handle->{rbuf} . ":\n"; }, on_eof => sub { my ($handle) = @_; print "ON_EOF\n"; }, on_error => sub { my ($handle, $fatal, $message) = @_; print "ON_ERROR ($fatal) ($message)\n"; }, ); print "Handle created :$handle:\n"; }; print "Loop started\n"; EV::run;