in reply to Re^3: how send message without new-line terminator on IO::Socket
in thread how send message without new-line terminator on IO::Socket

read is not ok, because is mapped on fread instead I used sysread.

I replaced the statemente :$sres = <$new_sock>; with the following code:

(mybe it should be helpfull to someone else )

    $rin="";
    $sres = "";
    vec($rin,fileno($new_sock),1) = 1;
    $nfound=select( $rin, undef, undef, .1 );
    while ( $nfound )
    {
          sysread( $new_sock, $c, 1 );
	  chomp $c;
	  $sres .= $c;
          $nfound=select( $rin, undef, undef, .1 );
    }

  • Comment on Re^4: how send message without new-line terminator on IO::Socket

Replies are listed 'Best First'.
Re^5: how send message without new-line terminator on IO::Socket (sysread chomp select)
by tye (Sage) on Jul 26, 2006 at 15:12 UTC
    sysread( $new_sock, $sres, 1024, length($sres) )

    would be more efficient (see sysread).

    Why are you chomping if you aren't sending newlines?

    Why are you exiting your loop if 1/10th of second passes with no input? Shouldn't you exit when you reach end-of-file instead?

    Why use select if you don't have anything asychronous to do? Just read until EOF, no?

    - tye        

      sysread( $new_sock, $sres, 1024, length($sres) )  would be more efficient (see sysread).


      Ok I follow your suggestion


      Why are you chomping if you aren't sending newlines?


      Ok.. it was an old statement used in some elder test , I removed it now


      Why are you exiting your loop if 1/10th of second passes with no input? Shouldn't you exit when you reach end-of-file instead?
      Why use select if you don't have anything asychronous to do? Just read until EOF, no?

      Both OK, in previous attempt I got the messages hang , waiting for more data, so I include the select statement.
      Now I tried without select and the test program still wotks well.
      In have to check if in the real program all this is still good, and the apply your suggestions also on it.
      thanks.