[problem]
You want to listen on a port, maybe to test firewalls! 🙂
Excellent introduction to client server software.
[/problem]
[solution]
Another use bit of socket programming, courtesy of Perl! 🙂
Extremely useful bit of Perl, which can be used with the other post on this site, to confirm network connectivity (port scanner).
This code (see example tab) will listen on a port (although be careful it is over 1024, unless you are running as root/admin).
[/solution]
[example]
perl -MIO::Socket -e '$srv=IO::Socket::INET->
new(LocalPort=>$ARGV[0],Type=>SOCK_STREAM,Reuse=>1,Listen=>5)
or die "Failed trying to listen on $ARGV[0]n";while($cl=$srv->accept()) { while() { print }
} close($socket);' port
Can also use it as a cheap chat service! 🙂 Everything gets echo’d through – so just telnet host port and type away! 🙂
Also see my port scan code at the reference tab.
[/example]
[reference]
[tags]Perl Socket Programming, Network Programming, Perl Port Listen, Perl Client Server demo, Perl Coding School[/tags]
[/reference]
If you have found my website useful, please consider buying me a coffee below 😉