I have been searching for sample program for sending multi-part/concatenated SMS using SMPP but couldn’t find any. On all sites/forums, description of UDH has been given which is quite helpful though, yet need was sample programs felt. So here is the one which I did using Logica Open SMPP API(I will refer it with ‘LOS’ onwards). This is almost same for all other available APIs too
I will not dwell much in the structure of UDH for long/concatenated SMS. Here is summary of fields:
Field1: (one byte) This is length of UDH. (UDH len is not field, but let us keep it simple for now)
Field2: (one byte) This is IE (Information Element Identifier). This decides whether CSMS ref number (Field 4) will be 1 byte or 2 bytes. In our case this will be 00 which makes it 1 byte. 08 is used for 2 bytes
Field3: Information Element data length. Keep in mind, Field1 and Field2 will be excluded from this. In our case, it will be 3
Field4: CSMS Reference number, any byte value
Field5: Total number of segments of SMS. (Each segment being of 153 chars max)
Field6: Sequence number of SMS part.
Sending multi-part/concatenated/long SMS using UDH can be summed up in the following steps:
· Set User Data Header Indicator(UDHI) which is done by setting 0x40 in ESM Class of the SMS
· Do not set SMS text in the SMS request object for message will be appended in UDH
· Split Long SMS in chunks of max characters 153 in each
· Set UDH field values as given above
· Append SMS text in UDH
LOS comes with a class org.smpp.test.SMPPTest. I have added a method in this class with the signature submitLong(). Complete method is in the attached file.
Concatenated/Long SMS part of the method is:
SubmitSM smRequest = new SubmitSM();
SubmitSMResp response;
--- --- --- Set other request values
smRequest.setEsmClass((byte)Data.SM_UDH_GSM); //Set UDHI Flag Data.SM_UDH_GSM=0x40
String[] splittedMsg = this.sptlitString(shortMessage, 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) randInt) ; //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_GSM7BIT);
smRequest.setShortMessageData(ed);
System.out.print("#" + i + " ");
System.out.println("Submit request " + smRequest.debugString());
response = session.submit(smRequest);
messageId = response.getMessageId();
}
}
That’s all!
Hope this will help you. I tried this with 2 other APIs and it worked fine but sometimes I got 0x58 (throttle error)
The way is same for all the API, you may just have to give a few moments to find out how API allows to set UDHI and takes UDH data.
Sunday, September 6, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment