Skip to content

Instantly share code, notes, and snippets.

@s1037989
Created January 16, 2014 15:48
Show Gist options
  • Save s1037989/8457175 to your computer and use it in GitHub Desktop.
Save s1037989/8457175 to your computer and use it in GitHub Desktop.
use Mojolicious::Lite;
use Socket;
get '/' => {text => 'Hello, World!'};
get '/connect' => sub {
my $self = shift;
my ($ip, $protocol, $port, $myhouse, $yourhouse, $log);
$ip = '192.168.0.52';
$port = '6335';
$protocol = getprotobyname('tcp');
socket(SOCKET, PF_INET, SOCK_STREAM, $protocol);
$yourhouse = inet_aton($ip);
$myhouse = sockaddr_in($port, $yourhouse);
$self->app->log->info("Connecting to $ip:$port");
if (!connect(SOCKET, $myhouse)) {
$self->render(text => 'KO');
} else {
$self->render(text => 'OK');
close SOCKET || die "close: $!";
}
};
app->start;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment