2

i am developing a sms gateway where i developed a smpp server. One of my client want to send message using a 3rd party tool. Everything is working fine. Except one. If client send long message more then 254 octets then short_message parameter contains udh property. I figured out that messages are coming in a sequence. I also noticed that buffer has a value of that sequence. Now i need to concate those multipart message into one. Here i stucked

this is my smpp server code

import { SUBMIT_SM } from './app/constants/smpp.constants';
import * as smpp from 'smpp';
import { BIND_TRANSCEIVER } from './app/constants';

export class SMPPTestServer {
  constructor() {
    this.init();
  }

  public async init() {
    const server = smpp.createServer((session: any) => {
      session.on(BIND_TRANSCEIVER, async (pdu: any) => {
        session.pause();

        const buffers = [];

        session.on(SUBMIT_SM, async (pdu: any) => {
          const udh = pdu.short_message.udh[0];

          session.send(
            pdu.response({
              sequence_number: pdu.sequence_number,
            }),
          );
        });

        session.send(pdu.response());
        session.resume();
      });
    });

    server.listen(2775);
    console.log('SMPP Test Server Listening On 2775');
  }
}

Here is a client code i am testing

var smpp = require('smpp');

function sleep(milliseconds) {
  return new Promise((resolve) => setTimeout(resolve, milliseconds));
}

var session = smpp.connect({
  url: 'smpp://localhost:2775',
  // url: 'smpp://157.230.248.140:2775',
  // url: 'smpp://157.230.248.140:2775',
  auto_enquire_link_period: 10000,
});

session.bind_transceiver(
  {
    system_id: 'reshop',
    password: 'reshop202',
  },
  async function (pdu) {
    const messages = ['dddd', 'hello world', 'from message analytica'];
    const concatRef = Math.floor(Math.random() * 255);

    for (let i = 0; i < messages.length; i++) {
      const smsPart = messages[i];
      const udh = new Buffer(6);

      udh.write(String.fromCharCode(0x5), 0); /* Length of UDH */
      udh.write(
        String.fromCharCode(0x0),
        1
      ); /* Indicator for concatenated message */
      udh.write(String.fromCharCode(0x3), 2); /* Subheader Length (3 bytes) */
      udh.write(
        String.fromCharCode(concatRef),
        3
      ); /* Same reference for all concatenated messages */
      udh.write(
        String.fromCharCode(messages.length),
        4
      ); /* Number of total messages in the split */
      udh.write(
        String.fromCharCode(i + 1),
        5
      ); /* Sequence number (used by the mobile to concatenate the split messages) */

      if (pdu.command_status == 0) {
        session.submit_sm(
          {
            destination_addr: '01636476123',
            short_message: { udh: udh, message: smsPart },
            source_addr: '8809612440278',
            // sequence_number: 99,
          },
          // {
          //   destination_addr: '01636476123',
          //   message_payload:
          //     "(CNN)Sme of the most damaging testimony against the police officer on trial over the death of George Floyd is coming from fellow cops. The second week of evidence against Derek Chauvin, who is charged with murdering Floyd, has moved on from wrenching eyewitness accounts of the Minnesota man's death, which sparked a worldwide racial reckoning. Prosecutors are now narrowing in on Chauvin's conduct in subduing Floyd, making a case that he acted outside reasonable police procedure.",
          //   source_addr: '8809612440278',
          //   sequence_number: 99,
          // },
          function (pdu) {
            console.log('[CLIENT => SUBMIT_SM]', pdu);
            console.log(i);

            if (pdu.command_status == 0) {
              // Message successfully sent
              console.log(pdu.message_id);
            }
          }
        );

        session.on('deliver_sm', async (pdu) => {
          if (pdu && pdu.receipted_message_id) {
            // console.log('[ON_DELIVER_SM]', pdu);
            session.send(
              pdu.response({
                sequence_number: pdu.sequence_number,
                message_id: pdu.receipted_message_id,
              })
            );
          }
        });

        console.log('Taking Nap');
        await sleep(10);

        // session.on('deliver_sm', function (pdu) {
        //   console.log('[CLIENT => DELIVER_SM]', pdu);
        // });
      }
    }
  }
);

0 Answers0