String sourceMsisdn = "1616";
String destinationMsisdn = "666111222";
MessageClass messageClass = MessageClass.CLASS1;
String messageBody = "Lorem ipsum dolor sit amet enim. Etiam ullamcorper. Suspendisse a pellentesque dui, non felis. Maecenas malesuada elit lectus felis, malesuada ultricies. Curabitur et ligula. Ut molestie a, ultricies porta urna.";
SMPPSession session = new SMPPSession();
session.addSessionStateListener(new SessionStateListenerImpl());
session.setMessageReceiverListener(new MessageReceiverListenerImpl());
try {
session.connectAndBind("localhost", 2775, new BindParameter(BindType.BIND_TRX, "smppclient", "password",
"cp", TypeOfNumber.UNKNOWN, NumberingPlanIndicator.UNKNOWN, null));
} catch (IOException e) {
System.err.println("Failed connect and bind to host");
e.printStackTrace();
}
// configure variables acording to if message contains national
// characters
Alphabet alphabet = null;
int maximumSingleMessageSize = 0;
int maximumMultipartMessageSegmentSize = 0;
byte[] byteSingleMessage = null;
if (Gsm0338.isEncodeableInGsm0338(messageBody)) {
byteSingleMessage = messageBody.getBytes();
alphabet = Alphabet.ALPHA_DEFAULT;
maximumSingleMessageSize = MAX_SINGLE_MSG_SEGMENT_SIZE_7BIT;
maximumMultipartMessageSegmentSize = MAX_MULTIPART_MSG_SEGMENT_SIZE_7BIT;
} else {
byteSingleMessage = messageBody.getBytes("UTF-16BE");
alphabet = Alphabet.ALPHA_UCS2;
maximumSingleMessageSize = MAX_SINGLE_MSG_SEGMENT_SIZE_UCS2;
maximumMultipartMessageSegmentSize = MAX_MULTIPART_MSG_SEGMENT_SIZE_UCS2;
}
// check if message needs splitting and set required sending parameters
byte[][] byteMessagesArray = null;
ESMClass esmClass = null;
if (messageBody.length() > maximumSingleMessageSize) {
// split message according to the maximum length of a segment
byteMessagesArray = splitUnicodeMessage(byteSingleMessage, maximumMultipartMessageSegmentSize);
// set UDHI so PDU will decode the header
esmClass = new ESMClass(MessageMode.DEFAULT, MessageType.DEFAULT, GSMSpecificFeature.UDHI);
} else {
byteMessagesArray = new byte[][] { byteSingleMessage };
esmClass = new ESMClass();
}
System.out.println("Sending message " + messageBody);
System.out.printf("Message is %d characters long and will be sent as %d messages with params: %s %s ",
messageBody.length(), byteMessagesArray.length, alphabet, messageClass);
System.out.println();
// submit all messages
for (int i = 0; i < byteMessagesArray.length; i++) {
String messageId = submitMessage(session, byteMessagesArray[i], sourceMsisdn, destinationMsisdn,
messageClass, alphabet, esmClass);
System.out.println("Message submitted, message_id is " + messageId);
}
System.out.println("Entering listening mode. Press enter to finish...");
try {
System.in.read();
} catch (IOException e) {
e.printStackTrace();
}
session.unbindAndClose();
}