Created
December 15, 2016 23:37
-
-
Save nicwolff/0549a79e56af5f4a97c2706c220f8ac4 to your computer and use it in GitHub Desktop.
Simple Perl test TCP server
This file contains hidden or 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/perl | |
use Socket; | |
# Set up listener | |
$on_port = $ARGV[0] || 25; | |
$proto = getprotobyname("tcp"); | |
socket (Server, PF_INET, SOCK_STREAM, $proto) || die ("socket"); | |
setsockopt(Server, SOL_SOCKET,SO_REUSEADDR,1) || die ("setsockopt"); | |
$pbind = sockaddr_in($on_port, $ARGV[1] ? inet_aton($ARGV[1]) : INADDR_ANY) || die ("sockaddr_in"); | |
bind(Server,$pbind) || die ("Can't bind: $!"); | |
listen(Server,SOMAXCONN) || die ("Can't listen: $!"); | |
# await a contact | |
while ($paddr = accept(Client, Server)) { | |
print Client "Hi there\n"; | |
close Client; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment