Pb with IO::Socket::INET and recv

Discussion in 'Perl Misc' started by Sébastien Cottalorda, Sep 5, 2003.

  1. Hi all,
    Since I migrate a client program to Mandrake 9.1 (kernel 2.4.21-0.13) and
    perl 5.8.0, this little program didn't work.
    The problem occured on the
    unless(recv...) line
    It always return me "false" => my program think that there was an error.
    If I remove the unless (recv...) check, it seems to work.


    Thanks in advance for any kind of help.

    Sébastien



    #!/usr/bin/perl -w
    use IO::Socket;
    use IO::Select;
    use strict;
    my $end_car="\r";
    my $time_out_sending = my $time_out_receiving = 30;
    my @recep = &envoie("Hello, How are you","192.168.0.1","45678","");
    foreach (@recep){ print "$_\n"}
    exit;


    sub envoie {
    my $to_send = $_[0];
    my $adr_ip= $_[1];
    my $por = $_[2];
    my $socket='';
    #=========================/ Socket creation \=========================
    unless ($socket = IO::Socket::INET->new(PeerAddr=> $adr_ip,
    PeerPort=> $por,
    Proto=> "tcp",
    Timeout=>10,
    Type=> SOCK_STREAM))
    {
    return "Cannot connect to $adr_ip:$por [email protected]";
    }
    my $s=IO::Select->new();
    $s->add($socket);
    #==========================/ Sending \================================
    if ($s->can_write($time_out_sending)){
    unless ($socket->send("$to_send"."$end_car",'')){ #>>>> SENDING
    $s->remove($socket);
    close($socket);
    return "Cannot Send $!";
    }
    }
    else { #------------> Time out <-------------
    $s->remove($socket);
    close($socket);
    return "TIME OUT sending datas";
    }
    #=========================/ Receiving \===============================
    my $data_read="";
    if ($s->can_read($time_out_receiving)){
    unless ($socket->recv($data_read,'1024')){ #<<<<< PROB HERE
    $s->remove($socket); # Always executed
    close($socket); # " "
    return "Cannot Receive $!"; # " "
    }
    $s->remove($socket);
    close($socket);
    return $data_read;
    }
    else { #------------> Time out <-------------
    $s->remove($socket);
    close($socket);
    return "TIME OUT receiving datas";
    }
    }
     
    Sébastien Cottalorda, Sep 5, 2003
    #1
    1. Advertisements

  2. Solved problem !!!!

    unless (defined $socket->recv($data_read, 1024, 0));

    Thanks to Paul GABORIT.

    Sébastien
     
    Sébastien Cottalorda, Sep 16, 2003
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.