Skip to content

Instantly share code, notes, and snippets.

@kramapet
Last active August 29, 2015 14:07
Show Gist options
  • Save kramapet/0084ef46c3aab5b8f931 to your computer and use it in GitHub Desktop.
Save kramapet/0084ef46c3aab5b8f931 to your computer and use it in GitHub Desktop.
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