javasmpp

Can't send special characters using Open-Smpp library in multi sms


I am using open-smpp library to communicate with SMSC. I am able to send both singe and multi SMS's, however I am having problem with special characters (šđžć) which in case of sending multi message(sendMultiSMS) are coming as '?'.

I read at https://en.wikipedia.org/wiki/Short_Message_Peer-to-Peer, that text in short_message field must match data_coding.

PSB, code parts of two methods. As per above wiki resource, I defined variable DATA_CODING which represents data_coding and I tried to encode text in short_message like this: submitSM.setShortMessage(message.getMessage(), Data.ENC_UTF16); - single message ed.appendString(messageAux, Data.ENC_UTF16); - multi message

So for single message, bellow combination is fine (DATA_CODING = (byte) 0x08 and Data.ENC_UTF16), characters are coming fine, but for multi-sms special characters are coming as '?'.

I tried all combinations like:
DATA_CODING = (byte) 0x01 and Data.ENC_UTF16
DATA_CODING = (byte) 0x08 and Data.ENC_UTF16
DATA_CODING = (byte) 0x01 and Data.ENC_UTF8
DATA_CODING = (byte) 0x08 and Data.ENC_UTF8
etc., but without success.

**private static final byte DATA_CODING = (byte) 0x08;**

public void sendSMS(XMessage message) throws SmppException
{ 
    .
    .
    .
    SubmitSM submitSM = new SubmitSM();
    setScheduleDate(message, submitSM);
    submitSM.setProtocolId(PROTOCOL_ID);
    **submitSM.setDataCoding(DATA_CODING);**
    submitSM.setSourceAddr(mSrcAddress);
    submitSM.setDestAddr(mDestAddress);
    submitSM.setSequenceNumber(message.getSequence());
    **submitSM.setShortMessage(message.getMessage(), Data.ENC_UTF16);**
    SubmitSMResp submitSMResp = mSession.submit(submitSM);
}

public void sendMultiSMS(XMessage message) throws SmppException
{
    .
    .
    .
    submitSMMulti = new SubmitSM();
    submitSMMulti.setProtocolId(PROTOCOL_ID);
    **submitSMMulti.setDataCoding(DATA_CODING);**
    setScheduleDate(message, submitSMMulti);
    submitSMMulti.setSourceAddr(mSrcAddress);
    submitSMMulti.setDestAddr(mDestAddress);
    submitSMMulti.setEsmClass((byte)0x40);

    messageArray = XSMSProcessUtil.getMultiMessages(message.getMessage(), numSegments);
    SubmitSMResp submitSMResp = null;
    for(int count = 0; count < messageArray.length; count++)
    {
        submitSMMulti.setSequenceNumber(message.getSequence() + count);
        messageAux = messageArray[count];
        ByteBuffer ed = new ByteBuffer();
        ed.appendByte((byte)5);
        ed.appendByte((byte)0x00);
        ed.appendByte((byte)3);
        ed.appendByte((byte)message.getSequence());
        ed.appendByte((byte)numSegments);
        ed.appendByte((byte)(count +1));
        **ed.appendString(messageAux, Data.ENC_UTF16);**
        submitSMMulti.setShortMessageData(ed);
        submitSMResp = mSession.submit(submitSMMulti);
    }
}

Solution

  • I found solution using information from this URL.
    Here is short explanation:

    The GSM character encoding uses 7 bits to represent each character, non-Latin-based alphabet languages usually use phones supporting Unicode. The specific character encoding utilized by these phones is usually UTF-16 or UCS-2. Both UTF-16 and UCS-2 use 16 bits to represent each character. Standard SMS messages have a maximum payload of 140 bytes (1120 bits). For Unicode phones, which use a 16-bit character encoding, this allows a maximum of 70 characters per standard SMS message. UDH takes up 6 bytes (48 bits) of a normal SMS message payload. So each individual concatenated SMS message can hold 67 characters: 1072 bits / (16 bits/character) = 67 characters

    I needed to lower maximal size of the message from 153 to 67 and use DATA_CODING = (byte) 0x08 and Data.ENC_UTF16.