hello, all monks:

I write a simple echo server and client script to test socket timeout. Originally, I think timeout in IO::Socket::INET means the sysread/syswrite will return a ETIMEOUT error if it can't read/write the message within the duration of the timeout. But from the result of my test, it seems that I am very wrong about this. Following is my simple code:

sever:
#!/usr/bin/perl use strict; use warnings; use IO::Socket::INET; my $listenSocket = IO::Socket::INET->new( 'LocalPort' => '12345', 'Listen' => SOMAXCONN, 'Reuse' => 1, 'Proto' => 'tcp', ) or die $@; my $conSocket = $listenSocket->accept; while ( defined $conSocket ) { my $rsp = q{}; $conSocket->sysread( $rsp, 20 ) or die $@; print "recv: $rsp\n"; $conSocket->syswrite( "hello, client!\n" ) or die $@; } ## end while ( defined $conSocket)
client:
#!/usr/bin/perl use strict; use warnings; use IO::Socket::INET; my $socket = IO::Socket::INET->new( 'Proto' => 'tcp', 'PeerAddr' => '172.16.249.232', 'PeerPort' => '12345', ) or die $@; $socket->timeout(2); while (1) { $socket->syswrite( "hello, server!\n") or die $!; my $rsp = q{}; $socket->sysread( $rsp, 20 ) or die $!; print "recv:$rsp\n"; sleep 1; } ## end while (1)

I run the server side script first, and then run the client side script, when the connection is established, and confirm that the two side can communicate with each other, then I disconnect the client side from the network, and wait for 2 seconds, but the client side didn't complain a ETIMEOUT error:(. So I think I misunderstood the meanning of the timeout in IO::Socket::INET.

Can anyone explain what does timeout means in socket? Thanks in advance.


In reply to what does timeout mean in IO::Socket::INET ? by sunshine_august

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.