Skip to content
This repository has been archived by the owner on Sep 18, 2021. It is now read-only.

Sending message longer than 160 characters using UDH #49

Closed
foreverdeepak opened this issue Jan 2, 2014 · 21 comments
Closed

Sending message longer than 160 characters using UDH #49

foreverdeepak opened this issue Jan 2, 2014 · 21 comments

Comments

@foreverdeepak
Copy link

Hi Joe,

First of all, Happy new year to you. Hope, you are doing good.

We are using cloudhopper-smpp to submit the SMS to SMSC. But, SMSC has a restriction that we cannot send the SMS longer than 160 characters. If you want then you have to set the UDH. I was looking for some example/documentation, but did not find any. Can you please help us with some code snippet where we can send the long messages using UDH.

Best Regards,
Deepak

@gabrielhof
Copy link

I'm using this way and it works fine:

byte[] message = "set your message here".getBytes();

SubmitSm submitSm = new SubmitSm();
//...
//set other properties
//...
submitSm.setShortMessage(new byte[0]);
submitSm.addOptionalParameter(new Tlv(0x0424, message)); //0x0424 is an optional parameter code for payload

//send the message

@foreverdeepak
Copy link
Author

I have already tried this option. But it is not working. SMSC team suggested to send UDH.

@4lex1v
Copy link

4lex1v commented Feb 21, 2014

We have the same problem. Some example using UDH to split long message would be great

@foreverdeepak
Copy link
Author

@wizardjedi
Copy link

Hi,

you can use GsmUtil from cloudhopper-commons

https://github.com/twitter/cloudhopper-commons/blob/ac71046783565fc3c6426a698c8f69334e159700/ch-commons-gsm/src/main/java/com/cloudhopper/commons/gsm/GsmUtil.java#L268

GsmUtil.createConcatenatedBinaryShortMessages - split byte array to parts and create proper UDH-headers in parts. You have only create message id.

Example:
byte[] encodedText = CharsetUtil.encode(message, encoding);

byte[][] msgParts;

Random random = new Random();
msgParts = GsmUtil.createConcatenatedBinaryShortMessages(encodedText, (byte) (id % 255));

Then you have to make a loop through all msgParts, create SUBMIT_SMs and send them.

@wizardjedi
Copy link

These unwanted symbols are bytes of udh header. Your cell phone use them for proper concatenation.

@wizardjedi
Copy link

Yes. But message have to be less then 140 bytes. In other words dont use concatenated messages.

@foreverdeepak
Copy link
Author

@aagiri : Normally, SMSC allows only 160 characters max. per SMS. If message goes beyond this limit, SMSC simply reject the message and does not deliver to sender. To solve this problem, UDH comes into picture. If a message has length more than 160 chars then it should be divided into multiple short messages for delivery (look at method sendLongMessage / splitUnicodeMessage). For example, if a message has 350 characters then it will be divided into 3 messages. Each message will contain the UDH information (packet sequence, referenceId etc. ) as given in the gist. Mobile devices has the capability to concatenate multiple messages containing UDH and displaying as a single SMS.

@krasa
Copy link
Contributor

krasa commented Oct 6, 2014

Not quite that, the message can have 140 bytes max. See http://stackoverflow.com/a/21121353/685796

@foreverdeepak
Copy link
Author

@aagiri
CHARSET_ISO_8859_15 supports single byte encoding, means one character will take one byte in encoding. Whereas, other charsets may use multi byte encoding, for example UTF-8 uses multi byte encoding. Hence, other charsets may cause the longer message than expected. In our case SMSC was supporting CHARSET_ISO_8859_15. So, you also need to check the with SMSC. Most of SMSC supports GSM-7 encoding.

@krasa
Copy link
Contributor

krasa commented Oct 13, 2014

@aagiri Well, technically you can send a longer message, but real SMSC will reject your message, while dummy testing SMSC will not.

@sybraimah
Copy link

@foreverdeepak I used the code in your link https://gist.github.com/foreverdeepak/9130661. The message is concatenated and sent but is received on the phone as a single 160 character message with questions marks in the front like this ...

??????testing three page message three page three page three page three page three page three page three page three page three page three page three page three

is there anything else I'm missing?
here is my code

byte[] textBytes = CharsetUtil.encode(text, CharsetUtil.CHARSET_UTF_8);
byte[][] msgParts = msgParts = splitUnicodeMessage(textBytes,134);
for(byte[] part:msgParts){
    SubmitSm submit = new SubmitSm();
    submit.setRegisteredDelivery(SmppConstants.REGISTERED_DELIVERY_SMSC_RECEIPT_REQUESTED);
    submitMsg.setSourceAddress(new Address((byte) 0x03, (byte) 0x00, sentFrom));
    submitMsg.setDestAddress(new Address((byte) 0x01, (byte) 0x01, sendTo));
    submit.setShortMessage(part);
    SubmitSmResp submitResp = session0.submit(submit, 10000);
}

@foreverdeepak
Copy link
Author

@sybraimah: You have spaces in starting of the text. Just trim the text (text.trim()) before encode.

@sybraimah
Copy link

@foreverdeepak thanks for hint
my colleague @kdjomeda has just finished implementing sending and receiving messages with opensmpp

@kdjomeda
Copy link

@foreverdeepak Do you want me to share the codes here? I don't mind. just to let you know that I have implemented that using version 3.0.0 (single and multiple page worked just fine at first try) but moving to jsmpp though. reason is simple, I don't really like the way delivery response registration is done and how the call back is done. Maybe I am missing something but not matter what value registered I only get submit_resp. I am going to explore jsmpp and post back here if it fits all my expectations

@TejasHJadhav
Copy link

I am trying to send concatenated SMS.My previous code(implemented by others) successfully sends 160 long SMS successfully.I am tryng to increase the length of SMS,so Spiled that msg in 153 each and trying to put UDH in each part.my previous SMS in septet .header have 6(6*8=48 and i want 49 that is 7 septet) octets.how to create that combination of Septet and octate.please help me.its urgent

@batman09
Copy link

In general SMSC takes care of splitting of long messages , adding udh headers to msg and sending them to mobile handset .In this case you have to use optional parameter to send long messages to SMSC.

In case if your SMSC doesnt support splitting then you have to send message to SMSC in parts by appending udh headers to each part .

refer https://gist.github.com/foreverdeepak/9130661 to achieve this .

For your information ,6 bytes are required to add udh headers.

I could not understand what u meant to say in the last two lines.

@krasa
Copy link
Contributor

krasa commented Dec 17, 2014

@batman09 In my experience ESME (the client) takes care of splitting.

@batman09
Copy link

@krasa depends on SMSC gateway.If it doessn't then u have to split !!!!

This question is off topic: Have you ppl ever implemented submit_multi using cloudhopper ?????

I referred this #33 but unable to implement .Help me out @kdjomeda @sybraimah @wizardjedi @gabrielhof @krasa @foreverdeepak @imade

@jjlauer
Copy link
Contributor

jjlauer commented Feb 27, 2015

Closing this issue as the discussion above provides lots of useful info for folks interested in splitting SMS. Lots of various ways depending on the SMSC.

@jjlauer jjlauer closed this as completed Feb 27, 2015
@shuklaabhi
Copy link

UDH is not supported in CDMA networks. Is there any other way we can send message larger than 160 both GSM and CDMA networks.

http://support.nowsms.com/discus/messages/12/60148.html

According to SMPP doc we can use TLV message payload and sar_msg_ref_num, sar_segment_seqnum and sar_total_segments and set short_message to null.
I tried it but it didn't work

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests