Sending Concatenated SMS with UDH using kannel
Join the DZone community and get the full member experience.
Join For FreeA normal SMS can contain upto 160 characters in GSM 7bit encoding.
For sending long messages that have more then 160 characters that message has to be splitted in multiple SMS with a UDH header added to them and sent one by one.
Whats a UDH:
UDH - User Data Header
It keeps the information about the message.
UDH is made up of 6 parts:
05 - This tells the length of UDH which is 5 bytes(total bytes fllowing this byte).
00 - IEL (Information Element Identifier). This indicates that this message is concatenated. This value will remain same
03 - This tells the length of incoming information field (ie more three bytes will be there in UDH).
AA- This is unique identifier of message.It remains same for all parts of message. It can be any unique byte. For eg F3
BB- This tells the total number of message parts. For example If you have a long message divided in two parts then this will be : 02
CC - The sequence number of this message. For example if you are sending first part of message then it will become 01 , if you are sending second part it will be 02.
So whole UDH will look like
Example UDH : 050003F30201
Sending A message with udh
As UDH is in hexadecimal format, while sending message with UDH then text should also be converted to hex format.
The code snippet shows simple example to send Message with UDH using XML POST in kannel
public class kannelSend{
public static void sendMessage(String inputXMLConnect) throws IOException {
String url = "http://localhost:13003/cgi-bin/sendsms";
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = null;
CloseableHttpResponse response = null;
InputStream in;
StringEntity entity = null;
entity = new StringEntity(inputXMLConnect, ContentType.create(
"text/xml"));
entity.setChunked(true);
try {
httpPost = new HttpPost(url);
httpPost.setEntity(entity);
response = httpClient.execute(httpPost);
LOG.info(response.getStatusLine());
in = response.getEntity().getContent();
String body = IOUtils.toString(in);
EntityUtils.consume(entity);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
finally{
response.close();
httpClient.close();
}
public static void main(String[] args) throws IOException {
String inputXMLConnect = "0000001234496e207468652063656c6c756c61722070686f6e6520696e6475737472792c206d6f62696c652070686f6e657320616e64207468656972206e6574776f726b7320736f6d6574696d657320737570706f727420636f6e636174656e617465642073686f7274206d657373616765207365727669636520746f206f766572636f6d6520746865206c696d69746174696f6e206f6e20746865206e050003F202016031abc123send";
submitKannelMessage(inputXMLConnect);
inputXMLConnect = "00000123756d626572206f66206368617261637465727320746861742063616e2062652073656e7420696e20612073696e676c6520534d532074657874206d657373616765207472616e736d697373696f6e2028776869636820697320757375616c6c7920313630292e050003F202026031abc123send";
submitKannelMessage(inputXMLConnect);
}
}
Opinions expressed by DZone contributors are their own.
Comments