Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Net::SMPP in Perl, how to send acknowledgement to SMSC from my ESME

Tags:

perl

sms

smpp

I am writing a Perl script that would act as a receiver & transmitter using Net::SMPP. When a mobile subscriber will send a message to a short code (say 123), it would reach to my SMPP account, and my SMPP application would read the message and reply with an acknowledgement to the user, some thing like "Thankyou for sending message". I receive message sent by the user to my SMPP app totally fine. The problem is sending back an acknowledgement (delivery_sm_resp) to the SMSC so that it removes that message from the stream, so that next message sent by other user can be collected. I tried using the function but I cant figure out where to get the message_id from the message received from SMSC to my ESME.

My code is.

my $transmitter = Net::SMPP->new_transmitter($host,port=> $port,system_id => '123',password  => '',) or die;

$receiver = Net::SMPP->new_receiver($host,system_id => '123',password => '',port => $port,)
    or die "Can't create server: $!";

while (1) {
    warn "Waiting for PDU";
    $pdu = $receiver->read_pdu() or die "$$: PDU not read. Closing connection";
    print "Received #$pdu->{seq} $pdu->{cmd}:". Net::SMPP::pdu_tab->{$pdu->{cmd}}{cmd} ."\n";
    warn Dumper($pdu);

    print "\n\n ** Hello ** " . $pdu->{message_id} . "\n ** now printing ** " . $pdu->{sm_default_msg_id};
    $transmitter->deliver_sm_resp( message_id => $pdu->{sm_default_msg_id}, seq => $pdu->{seq});
    $resp_pdu = $transmitter->submit_sm(
        destination_addr => $pdu->{source_addr},
        short_message    => "you sent a message with text " . $pdu->{short_message}
    ) or die "Response indicated error: " . $resp_pdu->explain_status();

}

The display of message i receive from the SMSC to my ESME is as follows. Please help me locating the message_id from it, which can be used in acknowledging the SMSC, so that it removes that message from the stream, and next message sent by other user can be entertained. Otherwise i receive the same PDU 3 times and till that timeout the next message cant be entertained.

Waiting for PDU at s.pl line 23.
Received #2 5:deliver_sm
$VAR1 = bless( {
             'source_addr_ton' => 1,
             'known_pdu' => 1,
             'schedule_delivery_time' => '',
             'protocol_id' => 0,
             'status' => 0,
             'short_message' => 'A',
             'dest_addr_npi' => 0,
             'source_addr' => '44702601843',
             'validity_period' => '',
             'registered_delivery' => 0,
             'dest_addr_ton' => 0,
             'seq' => 2,
             'data_coding' => 1,
             'service_type' => '',
             'replace_if_present_flag' => 0,
             'cmd' => 5,
             'priority_flag' => 0,
             'data' => '44702601843420A',
             'destination_addr' => '420',
             'esm_class' => 0,
             'sm_default_msg_id' => 0,
             'source_addr_npi' => 0,
             'reserved' => undef
           }, 'Net::SMPP::PDU' );
like image 531
Muzammil Avatar asked Nov 17 '25 14:11

Muzammil


1 Answers

Answer: I was checking this out more and found out that for sending acknowledgement response from ESME --> SMSC the following command should be used in the code. I hope it helps someone, sometime. :)

$receiver->data_sm_resp(message_id => $pdu->{sm_default_msg_id}, seq => $pdu->{seq});
like image 131
Muzammil Avatar answered Nov 19 '25 08:11

Muzammil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!