in reply to IO:Socket question... sort of :)
my ($acceptSock, $pid, $apprCode, $bufHdr, $buf, $length, $hdr, $req); my ($p1, $rsp, $rspMsg, $rspHdr, $msg); while (1) { printf("%sListening on port $args{p}\n", prHdr()); if (!($acceptSock = $listenSock->accept())) { print "bkpt 1: Accept failed: $!\n" if ($debug > 2); next; } # Spawn off a child to handle this connection $pid = fork(); die "Cannot fork: $!" unless defined($pid); # PID is zero when we're the child if($pid) { print "Parent continues\n" if ($debug > 2); next; } printf("%sAccepted connection from: %s\n", prHdr(), $acceptSock->pee +rhost()); srand(time); $apprCode = sprintf("%06d", int(rand 99999)+1); # Wait indefinitely for a message while (1) { print "Error reading 2-byte header: $!\n", last if (sysread($acceptSock, $bufHdr, 2) != 2); printf("%sReceiving request\n", prHdr()); # We got the 2-byte (data length) header $length = unpack("n", $bufHdr); print "$$: Length from request header = $length\n" if($debug > 2); print "Error length ($length) is < e-Header size ($EHDR_SIZE)\n", +last if ($length < $EHDR_SIZE); print "Error reading $length bytes of data: $!\n", last if (sysread($acceptSock, $buf, $length-2) != $length-2); if($debug > 1) { # Got the data, display it &hexDump($bufHdr . $buf); print "\n"; } }
|
|---|