26 January 2009 ~ 32 Comments

[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 fragements 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 fragements, 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 :-)

Tags: ,

32 Responses to “[SMPP] Sending long SMS through SMPP”

  1. Chintan 3 March 2009 at 11:14 am Permalink

    Thanks, It is small but give me very useful idea to search ahead for it.

  2. Vikram 20 August 2009 at 11:55 am Permalink

    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.

    • ashish 25 August 2009 at 6:59 am Permalink

      Vikram, I am not sure about how to send them. Can you try jsmpp forum.

  3. Vikram 28 August 2009 at 11:21 am Permalink

    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…

  4. Suren 4 September 2009 at 1:22 pm Permalink

    Hi,
    For each SubmitSM of the message fragment, do we get a SubmitSMResp?
    Pls clarify

    • ashish 5 September 2009 at 3:54 pm Permalink

      Yes it will. try it with real SMSC

  5. Suren 7 September 2009 at 7:55 am Permalink

    Thanx a lot!!

  6. Tommy 24 September 2009 at 1:54 pm Permalink

    Can anyone told me how can I add the optional paramter after the mandatory parameter. Can give me a example?

  7. Ruwan 19 October 2009 at 11:41 am Permalink

    Can any body, please share java code to send Long SMS messages using SMPP Version 3.4?

  8. Arvind 5 November 2009 at 10:23 am Permalink

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

    Thanks in advance!!

    • ashish 7 November 2009 at 10:28 am Permalink

      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.

  9. Arvind 9 November 2009 at 1:29 pm Permalink

    Thanks for the quick reply Ashish

  10. Sebastian 3 December 2009 at 3:33 am Permalink

    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.

  11. NAVEEN JAIN 2 June 2010 at 10:02 am Permalink

    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.

  12. Rakesh Kumar 10 June 2010 at 12:37 pm Permalink

    Hi can any body tell me how to send long concatenated sms using Logica smpp. Can somebody give me code to send long sms Please help.Thanks in advance.

  13. ram 10 June 2010 at 2:28 pm Permalink

    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……..

  14. Bunyipoz 5 August 2010 at 6:06 am Permalink

    Anyone managed to send long Unicode messages with the logica smpp library?

  15. bunyipoz 6 August 2010 at 6:17 am Permalink

    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.

    • ashish 6 August 2010 at 7:27 am Permalink

      Can you share the sample code with other? would be great. Thanks!

      • Lamine OUADJAOUT 1 January 2011 at 4:22 am Permalink

        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=0×40

        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) 0×00); // 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);
        }

        • Rikaelrick 28 January 2011 at 8:11 pm Permalink

          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?

  16. Lamine OUADJAOUT 1 January 2011 at 4:24 am Permalink

    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];
    }
    }

  17. Lamine OUADJAOUT 1 January 2011 at 4:26 am Permalink

    the code that I posted work with SMPP Logica 1.3, & I am searching how to send Long Arabic (UCS2) Unicode SMS :S

  18. Lamine OUADJAOUT 2 March 2011 at 12:45 am Permalink

    for long unicode UCS2 SMS I tested with logica today it’s working :D

    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=0×40
    msg.setDataCoding((byte) 0×08);
    ByteBuffer ed = new ByteBuffer();
    ed.appendByte((byte) 6); // UDH Length
    ed.appendByte((byte) 0×08); // 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);

    }

  19. Dharmendra Singh 9 March 2011 at 2:43 pm Permalink

    Hi,

    Can anyone send the sample java code to send Long messages using Logica SMPP API’s version 1.3.

    Thanks in advance.

    Dharmendra Singh

  20. Nihanth 25 March 2011 at 11:58 am Permalink

    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.

  21. Ho Viet Hong 30 May 2011 at 8:33 am Permalink

    You can show you how long the SMS through SMPP using C #

  22. Eric 22 September 2011 at 1:00 pm Permalink

    Hi,
    How to add the sar_msg_ref_num into PDU?

  23. Eric 22 September 2011 at 1:10 pm Permalink

    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?

  24. Max 24 October 2011 at 7:26 pm Permalink

    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 !!

    • MONICA 8 November 2011 at 7:44 pm Permalink

      Hi,

      Can you help me please, i’m facing the same problem.
      Did you find the cause of this exception.

      Thanks in advance.

  25. Max 24 October 2011 at 7:34 pm Permalink

    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


Leave a Reply