Greetings experts,

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


In reply to Checking if a socket has some data to read by perlgsm

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.