Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6356483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:58:17+00:00 2026-05-24T22:58:17+00:00

I have a simple script that should bind to an SMSC and listen for

  • 0

I have a simple script that should bind to an SMSC and listen for incoming messages. The problem I’m having is that it will time out if it doesn’t receive any messages.

Here is the script:

#!/usr/bin/perl

use Net::SMPP;
use Data::Dumper;
$Net::SMPP::trace = 1;

$smpp = Net::SMPP->new_receiver('--removed--',
                                port => '--removed--',
                                system_id => '--removed--',
                                password => '--removed--',
                                ) or die;

while (1)
{       
    $pdu = $smpp->read_pdu() or die;

    print "Received #$pdu->{seq} $pdu->{cmd}:". Net::SMPP::pdu_tab->{$pdu->{cmd}}{cmd} ."\n";
    print "From: $pdu->{source_addr}\nTo: $pdu->{destination_addr}\nData: $pdu->{data}\n";
    print "Messsage: $pdu->{short_message}\n\n";
}

Here’s the error I’m getting:

premature eof reading from socket at /usr/lib/perl5/site_perl/5.8.8/Net/SMPP.pm line 2424.
$VAR1 = undef;

And here’s the relevant sub from SMPP.pm:

sub read_hard {
    my ($me, $len, $dr, $offset) = @_;
    while (length($$dr) < $len+$offset) {
        my $n = length($$dr) - $offset;
        eval {
            local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
            alarm ${*$me}{enquire_interval} if ${*$me}{enquire_interval};
            warn "read $n/$len enqint(${*$me}{enquire_interval})" if $trace>1;
            while (1) {
                $n = $me->sysread($$dr, $len-$n, $n+$offset);
                next if $! =~ /^Interrupted/;
                last;
            }
            alarm 0;
        };
        if ($@) {
            warn "ENQUIRE $@" if $trace;
            die unless $@ eq "alarm\n";   # propagate unexpected errors
            $me->enquire_link();   # Send a periodic ping
        } else {
            if (!defined($n)) {
                warn "error reading header from socket: $!";
                ${*$me}{smpperror} = "read_hard I/O error: $!";
                ${*$me}{smpperrorcode} = 1;
                return undef;
            }
            #if ($n == 0) { last; }
            if (!$n) {
                warn "premature eof reading from socket";
                ${*$me}{smpperror} = "read_hard premature eof";
                ${*$me}{smpperrorcode} = 2;
                return undef;
                #return 0;
            }
        }
    }
    #warn "read complete";
    return 1;
}

In the sub, the if statement it’s hitting is the one where $n is 0 or undef.

My guess is that the socket is timing out and disconnecting. How can I keep the listener up indefinitely?

In addition, this listener blocks while waiting for a pdu. Is there a way to listen without blocking?

I’m a Telecom Engineer who does programming on the side, and I’ve gone through all the material I could find but couldn’t find an answer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:58:19+00:00Added an answer on May 24, 2026 at 10:58 pm

    It looks as if the sysread() call simply returns 0. It can do that only, if the connection status is known to be disconnected. Since your side did not disconnect or timeout, i would deduce that the remote side disconnected. If a timeout would have occured on your side, you should not have been able to see the premature eof... message.

    So, you are already ‘keeping the listener up indefinitely‘, since you do not set the enquire_interval option.

    Regarding ‘Is there a way to listen without blocking?‘ the description section describes asynchronous mode at the end: Module can also be used asynchronously by specifying async=>1 to the constructor. You have to implement the data polling then yourself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple python script that should scan a text file, which
I have a simple PHP script that will either serve up a streaming ASF
I have a simple script that should cause one of three divs to be
I have a simple script that does some search and replace. This is basically
I have a simple Python script that I want to stop executing if a
I have a simple PowerShell script that uses WMI to create a web site
I have a simple bat script that copies files from an known directory to
I have a simple Python script that uses the socket module to send a
I have a very simple greasemonkey script that I want to call an already
I have a very simple bit of script that changes the status of an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.