[SMPP] Sending long SMS through SMPP

SMS is designed to send small text messages upto 140 chars. It actually depends upon the encoding. Using 7 bit encoding, you can send 160 chars, using Unicode, you can only send 70 chars. The data is carried in User Data section.

This post talks about ways of sending Long message using SMPP

Using SMPP we can send long SMS by two means

Using Payload option

Submit SM PDU has a field called message_payload. Set the data in it and you can send upto 64K octets. But this option is not supported by a lot of provider. Verify with your provider, if they support the same.

Using Message fragementation

This format is more common and widely supported. Essentially, the long SMS is divided into smaller messages and send with a particular format, by setting UDH.

The key TLV options used are

sar_msg_ref_num - The reference number for a particular concatenated short message

sar_total_segments - Indicates the total number of short messages within the concatenated short message

sar_segment_seqnum - Indicates the sequence number of a particular short message fragment within the concatenated short message

How do you set these, depends upon the SMPP library you use. Will brief the algo

 

  • Break the long sms into parts, so that fragement can fit into single Submit SM PDU
  • The total number of fragments shall give the value of sar_total_segments
  • Generate a unique identifier value, this becomes the values of sar_msg_ref_num
  • Now in a loop send the message fragments, with values in step above. sar_segment_seqnum values shall be the value of the loop count (ensure that it starts from 1)

This is it 🙂

39 thoughts on “[SMPP] Sending long SMS through SMPP

  1. Hi,
    I am unable to send some special characters through smpp like £(pound) ,• (bullet).

    can you tell me how to generate unique sar_msg_ref_num for messages.I am using random number to generate for this.But some times we may get same random number diff requests.In that case both messages will be failed.

  2. Hi,
    I am getting special chracters through smpp using my java code..
    Now I am gettting diff problem.I am not getting long sms in one updation.In several updation I am getting complete long sms.

    Is there any way to get complete sms in one updation???
    Please help me…

  3. How does JSMPP send 3000 – 5000 messages per second?
    Meaning, is this by creating multiple threads or any particular mechanism.

    Thanks in advance!!

    • Yup it uses Executors for the same. Though the number is not guranteed. A lot depends on how soon the SMPP Server is responding back to requests.

  4. What do you mean when you say by setting UDH?
    There is a way of adding chars to the PDU but is not working on my SMPP Client
    I think it’s because I’m not reciving the sm_resp from the SMSC and using the value.
    Can you help me giving me a php code example of how you do this?
    Thanks a lot.

  5. Hi Ashish,

    I have a query with regard to fragmentation. I need to send a long message using fragmentation i.e. dividing a long message into multiple short messages. Now, this has to be done along with encoding, say GSM 7-Bit. There are two scenarios:

    a) Need to send fragments using SAR TLVs. The question arises whether I will fragment messages first and then encode it or other way. Let’s say I have original message spanning (in ASCII) 400 octets. Now, If I encode this message into GSM 7-Bit, then it converts to 350 octets (400 * 7/8). If I follow encode first, fragment next, then it means 3 fragments of 140, 140, 70 octets. What is the ideal way of doing it?

    b) Need to send fragments using UDH. I have same question over ordering of encoding & fragmentation.

    Please reply ASAP.

  6. hi
    any one reply me plz…
    i am send sms using jsmpp the msg send successfuly but cant able to read….it says “Unable to open. Message format not supported”
    i am new for this…
    how can identify find the error i dont knw wat to do..any one helpme its urgent……..

  7. Figured it out. I had correctly constructed the UDH bytes and put the split message into a bytebuffer. But when I put the buffer back into a String I forgot to tell it the encoding to use.

      • try
        {
        if(Text_SMS.length() > 160)
        {
        //SMS length is more than 160 Char

        SubmitSM smRequest = new SubmitSM();
        //Set other request values

        smRequest.setEsmClass((byte)Data.SM_UDH_GSM); //Set UDHI Flag Data.SM_UDH_GSM=0x40

        String[] splittedMsg = this.SplitByWidth(Text_SMS, 153);

        int totalSegments = splittedMsg.length;

        //iteerating on splittedMsg array. Only Sequence Number and short message text will change each time

        for (int i = 0; i < totalSegments; i++) {

        ByteBuffer ed = new ByteBuffer();

        ed.appendByte((byte) 5); // UDH Length
        ed.appendByte((byte) 0x00); // IE Identifier
        ed.appendByte((byte) 3); // IE Data Length
        ed.appendByte((byte) 2) ; //Reference Number
        ed.appendByte((byte) totalSegments) ; //Number of pieces
        ed.appendByte((byte) (i+1)) ; //Sequence number

        //This encoding comes in Logica Open SMPP. Refer to its docs for more detail

        ed.appendString(splittedMsg[i], Data.ENC_ASCII);

        smRequest.setShortMessageData(ed);

        smRequest.setSourceAddr(SourceAddr);
        smRequest.setDestAddr(DestAddr);

        resp = Server.session.submit(smRequest);

        Date maDate = new Date();
        if (resp.getCommandStatus() == Data.ESME_ROK) {
        Log(MSISDN + " " + maDate.toLocaleString() + " : part "+(i+1)+"/"+totalSegments+" submitted. Status=0");
        Thread.sleep(100);
        }
        else
        {
        Log(MSISDN + " " + maDate.toLocaleString() + " : part "+(i+1)+"/"+totalSegments+" submission failed. Status=" + resp.getCommandStatus());
        //envoyé l'erreur au client
        ByteSend= (MSISDN + " NOK").getBytes();
        Out.write(rsaEncrypt(ByteSend));
        break;
        }
        }
        ByteSend= (MSISDN + " OK").getBytes();
        Out.write(rsaEncrypt(ByteSend));

        }
        else // SMS length is less than 160 Char
        {
        SubmitSM msg = new SubmitSM();
        msg.setSourceAddr(SourceAddr);
        msg.setDestAddr(DestAddr);
        msg.setShortMessage(Text_SMS);
        resp = Server.session.submit(msg);
        Date maDate = new Date();
        if (resp.getCommandStatus() == Data.ESME_ROK)
        {
        Log(MSISDN + " " + maDate.toLocaleString() + " Message submitted. Status=0");
        ByteSend= (MSISDN + " OK").getBytes();
        Out.write(rsaEncrypt(ByteSend));

        }
        else
        {
        Log(MSISDN + " " + maDate.toLocaleString() + " Message submission failed. Status=" + resp.getCommandStatus());
        //envoyé l'erreur au client
        ByteSend= (MSISDN + " NOK").getBytes();
        Out.write(rsaEncrypt(ByteSend));
        }
        }

        }
        catch (Exception e)
        {
        Log(String.valueOf(e.fillInStackTrace()));
        fichierSortie.println (e.toString() + ": dans le MSISDN " + MSISDN);
        }

        • Hello, i have a question.

          What is the library (and version of it) you use in this example? It looks like Java SMPP Library by Logica, but in version that I found (The Java SMPP Library version 1.3) I dont see the method setShortMessageData( ByteBuffer byteBuffer ) in class SubmitSM.

          Did you add it to the library by yourself?
          If not, can you put correct link to the library you use?

  8. for the method that spleet the SMS text 🙂

    public String[] SplitByWidth(String s, int width) throws Exception
    {
    try
    {

    if (width==0)
    {
    String[] ret = new String[1];
    ret[0]=s;
    return ret;
    }
    else
    {

    if (s.isEmpty()) return new String[0];
    else
    {

    if (s.length() <= width)
    {
    String[] ret = new String[1];
    ret[0]=s;
    return ret;
    }
    else
    {
    int NumSeg = s.length() / width + 1;
    String[] ret = new String[NumSeg];
    int startPos = 0;

    for (int i = 0; i < NumSeg – 1; i++)
    {
    ret[i] = s.substring(startPos,((width*(i+1))));
    startPos = (i+1)*width;
    Log(ret[i]);

    }
    ret[NumSeg-1] = s.substring(startPos,s.length());
    return ret;
    }
    }
    }

    }
    catch (Exception e)
    {
    Log(String.valueOf(e.fillInStackTrace()));
    return new String[0];
    }
    }

  9. for long unicode UCS2 SMS I tested with logica today it’s working 😀

    this is the code:

    Message =”لحمدُ لله ربِّ العالمين، والصلاةُ والسلامُ على مَنْ أرسله اللهُ رحمةً للعالمين، وعلى آله وصَحْبِهِ وإخوانِه إلى يوم الدِّين”;
    String[] splittedMsg = Main.SplitByWidth(Message, 63);

    int totalSegments = splittedMsg.length;

    //iteerating on splittedMsg array. Only Sequence Number and short message text will change each time
    for (int i = 0; i < totalSegments; i++) {
    SubmitSM msg = new SubmitSM();
    msg.setSourceAddr(SourceAddr);
    msg.setEsmClass((byte)Data.SM_UDH_GSM); //Set UDHI Flag Data.SM_UDH_GSM=0x40
    msg.setDataCoding((byte) 0x08);
    ByteBuffer ed = new ByteBuffer();
    ed.appendByte((byte) 6); // UDH Length
    ed.appendByte((byte) 0x08); // IE Identifier
    ed.appendByte((byte) 4); // IE Data Length
    ed.appendByte((byte) 00) ; //Reference Number 1st Octet
    ed.appendByte((byte) 00) ; //Reference Number 2nd Octet
    ed.appendByte((byte) totalSegments) ; //Number of pieces
    ed.appendByte((byte) (i+1)) ; //Sequence number
    //This encoding comes in Logica Open SMPP. Refer to its docs for more detail
    ed.appendString(splittedMsg[i], Data.ENC_UTF16_BE);
    msg.setShortMessageData(ed);
    System.out.println(splittedMsg[i]);
    DestAddr.setAddress("213661133673");// 213661686742 0661686746 0661698177 0661686742 0661502966
    msg.setDestAddr(DestAddr);
    resp = session.submit(msg);

    }

  10. Hi,
    I have some problems regarding sms sending. Can some one please give me an idea on this regards.

    When sending encoding the message for sending concatenated sms in GSM7-bit encoding, do we have to do the packing of bytes??

    In the SMPP specification it is said that data_coding value 0 means SMSC default alphabet. Does this refers to GSM7, GSM7packed or does it depends on the SMSC??

    Thanks and regards,
    Nihanth.

  11. I have 2 messages:
    – “This is a message 001” with the PDU in normal format: 0000004B0000000400000000000000020001013139303035373135393200010130313233363734353737380000000300000000000015546869732069732061206D65737361676520303031
    – “This is a message 002” with the PDU in normal format: 0000004B0000000400000000000000020001013139303035373135393200010130313233363734353737380000000300000000000015546869732069732061206D65737361676520303032

    —> How to add the sar_msg_ref_num,sar_total_segments,sar_segment_seqnum into these PDUs?

  12. Hi,

    I have used Logica SMPP code with a client page. I am getting an error :
    Exception: com.logica.smpp.pdu.InvalidPDUException
    PDU debug string: (submit_resp: (pdu: 16 80000004 439 2) )
    Underlying exception: com.logica.smpp.util.NotEnoughDataInByteBufferException: Not enough data in byte buffer. Expected 1, available: 0.

    Did anyone came across it. Or anyone with a solution . Pls Suggest !!

  13. Also find the Log details :

    main: Session.send(Request) trying to create pdu from unprocessed buffer (1)
    07:28:57 main: Session.send(Request) PDU.setData() parsing header 00000019800000090000000000000001 (5)
    07:28:57 main: Session.send(Request) PDU.setData() parsing body 62726d000210000134 (5)
    07:28:57 main: Session.send(Request) have 5 bytes left. (5)
    07:28:57 main: Session.send(Request) received complete pdu(bindresp: (pdu: 25 80000009 0 1) brm 52) (1)
    07:28:57 main: Session.send(Request) there is 0 bytes left in unprocessed buffer (1)
    07:28:57 main: Session.send(Request) ReceiverBase.receivePDUFromConnection finished (3)
    07:28:57 main: Session.send(Request) Got pdu (bindresp: (pdu: 25 80000009 0 1) brm 52) (1)
    07:28:57 main: Session.send(Request) Got response(?) pdu (bindresp: (pdu: 25 80000009 0 1) brm 52) (4)
    07:28:57 main: Session.send(Request) checking response if it’s what we expected. (4)
    07:28:57 main: Session.send(Request) exited

  14. Hi ,
    I am also using smpp protocol.I am sending the long unicode message with encoding format as UTF-16 for encoding the unicode message and using setmessagPayLoad(buffer bb)function for sending the long message. This method is defined in submit_sm class of smpp protocol.For me the receiver is getting the empty message suggest what to do so that receiver will get the correct encoded message.

  15. getting below error

    SMPPSender.java:479: error: ByteBuffer is abstract; cannot be instantiated
    ByteBuffer ed = new ByteBuffer();

    please help on this

  16. Hello folks,

    There is another way of sending a long message (more than 140 octets ) using 3GPP TS 23.040 supported User Data Header(UDH) apart form using SAR TLVs or mesage_payload TLV.

    The UDH is more suitable when ESME is sending this message to SMSC (and the finally to a customer handset). Why ? because in this case SMSC needs to do very limited processing for building TPDU comparing with the TLV model. The contents of short_message will be copied and put into TP-UD field of TPDU – No further processing required. Here are the steps:

    1. ESME should set the UDHI bit in esm_class of submit_sm – indicating that the short_message has user data header in addition to actual sms text.
    2. Put the UDH and sms body in the short_message or message_payload parameter of submit_sm.
    3. Submit all segments by changing appropriate values of user data header –
    Message identifier (same for all segments of a long message)
    Message Parts (Total number of segments – same for all segments)
    Message Part Number (1 to value of Message Parts)

    On receiving these segments, SMSC will first accumulate all these and then will try to deliver to end user.

Leave a Reply

Your email address will not be published. Required fields are marked *