cstrong has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I hope you can help, as I've been looking everywhere for an answer!

I have a program which connects to a remote server (using Net::Telnet) and sends test transactions. I have a requirement to measure the various stages of the transaction. I can do this using Time::HiRes, however I have a problem in that when I do telnet->close, the close is handed off to the TCP stack and the program loops round again sending off a new transaction before the socket close is completely finished (this is over GPRS so it takes a while!).

The prblem is that $s2 and $3 are simply how long it takes the program to hand the close off to the TCP stack rather than the actual time it took to close the socket.

Is there any way to force the Perl program to wait for ACKs and FIN packets rather then letting the TCP stack handle them? I would be willing to recode my program using IO::Socket::INET if it helps at all.
##open socket $t0 = [gettimeofday]; #Start overall txn timer $s0 = [gettimeofday]; #Start socket creation timer &connect_server($ip,$port); #Make a telnet connection to $s1 = [gettimeofday]; #End socket creation timer ##send / receive msgs $m0 = [gettimeofday]; #Start TXN timer for message payloads $telnet->put("$octmsg1"); #"put" 11st octal txn on the wire (send n +o CR) $telnet->waitfor(/02.*/); #Expect a response @list = $telnet->get; #Gather the response $telnet->put("$octmsg2"); #"put" 2nd octal txn on the wire (send no + CR) $m1 = [gettimeofday]; #End TXN timer for message payloads ##Close socket $s2 = [gettimeofday]; #Start FIN timer $telnet->close; $s3 = [gettimeofday]; #End FIN timer t1 = [gettimeofday]; #End overall txn timer
I'm running on XP, but if its any easier I can also run on Linux

Replies are listed 'Best First'.
Re: Waiting for ACKs and FINs
by Fletch (Bishop) on Nov 07, 2008 at 17:05 UTC

    Perhaps come at the problem from a different angle: rather than try and usurp the TCP stack, use Wireshark or the like to get timings directly from captured packets and then parse its output to get your report.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: Waiting for ACKs and FINs
by jettero (Monsignor) on Nov 07, 2008 at 17:30 UTC
    What Fletch said, or possibly try Net::Pcap -- which is pretty much the wireshark backend.

    -Paul