Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Pb with IO::Socket::INET and recv

Reply
Thread Tools

Pb with IO::Socket::INET and recv

 
 
Sébastien Cottalorda
Guest
Posts: n/a
 
      09-05-2003
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 $@";
}
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";
}
}

--
[ retirer NOSPAM pour répondre directement
remove NOSPAM to reply directly ]
 
Reply With Quote
 
 
 
 
Sébastien Cottalorda
Guest
Posts: n/a
 
      09-16-2003
Sébastien Cottalorda wrote:

> 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 $@";
> }
> 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";
> }
> }
>


Solved problem !!!!

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

Thanks to Paul GABORIT.

Sébastien


--
[ retirer NOSPAM pour répondre directement
remove NOSPAM to reply directly ]
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to empty the recv buffer without recv() ? deepak nayak C++ 3 10-25-2007 08:14 AM
Crazy Send and Recv behaviour ifmusic@gmail.com C Programming 4 10-20-2005 02:54 AM
strange problem with send() and recv() Tom C Programming 6 08-14-2005 05:32 PM
Recv and fwding in multi-threaded sockets programming Johny Franslay Java 1 03-01-2004 08:04 PM
transfer file using recv() and fwrite() michelle C Programming 2 06-26-2003 05:17 PM



Advertisments