perlgsm has asked for the wisdom of the Perl Monks concerning the following question:
I am using 'Net::SMPP' to have a transceiver SMPP connection(tcp) to exchange some SMSs.
The read_pdu() function offered by the library blocks until some data is available. In order to fix this I'm using IO::Select->can_read() to check if some data is available of the wire, so that I can execute the read_pdu to actually read the data.
The problem is can_read is always returning an undef, I tried many tricks and methods, but none have worked.
I'm attaching my code here.
#!/usr/bin/perl use IO::Socket; use IO::Select; use Data::Dumper; use Net::SMPP; #use warnings; $tt=time(); $host="some_ip"; $port=7661; $smpp = Net::SMPP->new_transceiver($host, port=>$port, system_id => 'test', password => 'test', system_type => 'smpp' # sadsadsdsdsasource_porty => 60001, ) or die; $port=`netstat -an|grep 7661`; #print "$port\n"; if($port=~/tcp\s+\d\s+\d\sxx\.xxx\.xx\.xx:(\d+)\s+xx\.xxx\.xx\.xx:7661 +.*ESTABLISHED/) { $pt=$1; } $lsn = new IO::Socket::INET(Listen => 2, LocalAddr =>'localhost',Local +Port => $pt); print "\nlistening on port : "; print $lsn->sockport(); print "\n"; $sel = new IO::Select( $lsn ) or die "cant bind"; print "count".$sel->count() or die "cant get count"; print "before while\n\n"; while(1) { print "here\n"; $results = $sel->can_read(0);# or die "cant read"; #print Dumper @results; print "\n****Outside if****"; print "results== $results\n"; if(@results!=undef) { print "\ninside if"; $pdu = $smpp->read_pdu(); $a=$pdu->{source_addr}; $b=$pdu->{destination_addr}; $msg=$pdu->{short_message}; $pay=$pdu->{message_payload}; print "Msg: $a->$b\t$msg\t$pay\n\n"; } else { print "hello"; print $sel->count(); } }
Any idea would be highly appreciated.
Many thanks, perlgsm
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Checking if a socket has some data to read
by 5mi11er (Deacon) on Jun 13, 2013 at 17:57 UTC | |
by perlgsm (Initiate) on Jun 14, 2013 at 12:28 UTC | |
by 5mi11er (Deacon) on Jun 14, 2013 at 16:16 UTC | |
by perlgsm (Initiate) on Nov 08, 2013 at 09:18 UTC | |
by perlgsm (Initiate) on Nov 18, 2013 at 15:13 UTC |