Last active
August 29, 2015 14:07
-
-
Save kramapet/0084ef46c3aab5b8f931 to your computer and use it in GitHub Desktop.
Perl - binding socket on port
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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);' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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