Instantly share code, notes, and snippets.

Embed
What would you like to do?
Perl - binding socket on port
$ perl -mIO::Socket -e 'my $s = new IO::Socket::INET(Listen => 1, LocalAddr => "localhost", LocalPort => 8888, Proto => "tcp"); my $data = $s->accept(); while (<$data>) { print $_; } close($s);'
#!/usr/bin/env perl
use strict;
use warnings;
use IO::Socket;
sub help {
print STDERR "$0 <addr> <port>\n"
}
if (@ARGV != 2) {
help();
exit(255);
}
my $sock = new IO::Socket::INET(
LocalAddr => $ARGV[0],
LocalPort => $ARGV[1],
Proto => 'tcp',
Listen => 1) or die "$!";
my $data = $sock->accept();
while (readline $data) {
print $_;
}
close($sock);
exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment