I am using JSMPP
I have connected with the smsc
and I am trying to send messages and trying to receive the delivery receipts
I am facing a problem I just want to create a single connection. If you can help me out here that would be really great. My code is:
package com.jsmpp.dialerintegration;
public class SenderToMsgBroker{
public String sendingSms(String [] mobileNo) {
String [] receiverMobileNo = mobileNo;
String blankMSG="";
SMPPSession session = new SMPPSession();
try{
session.connectAndBind("ip", port,
new BindParameter(BindType.BIND_TRX, "username", "password",
"cp", TypeOfNumber.UNKNOWN,
NumberingPlanIndicator.UNKNOWN, null),1000*60*30,session);
System.out.println("Connection Established And SessionId :"+session.getSessionId());
System.out.println("SessionState"+session.getSessionState());
}
catch (IOException e) {
System.err.println("Failed connect and bind to host");
e.printStackTrace();
}
try {
for(int i=0;i<receiverMobileNo.length;i++)
{
session.setMessageReceiverListener(new MessageReceiverListenerImpl());
System.out.println("Trying to send the message->>>");
String messageId = session
.submitShortMessage(
null,
TypeOfNumber.UNKNOWN,
NumberingPlanIndicator.UNKNOWN,
"51633",
TypeOfNumber.UNKNOWN,
NumberingPlanIndicator.UNKNOWN,
receiverMobileNo[i],
new ESMClass(),
(byte) 0,
(byte) 1,
null,
null,
new RegisteredDelivery(
SMSCDeliveryReceipt.SUCCESS_FAILURE),
(byte) 0,
new GeneralDataCoding((byte) 0xc0),
(byte) 0,blankMSG.getBytes());
System.out.println("Message submitted, message_id is " + messageId);
System.out.println("Message Receiver Mobile No is :"
+ receiverMobileNo[i]);
}
} catch (PDUException e) {
// Invalid PDU parameter
System.err.println("Invalid PDU parameter");
e.printStackTrace();
return "PDUException";
} catch (ResponseTimeoutException e) {
// Response timeout
System.err.println("Response timeout");
e.printStackTrace();
return "ResponseTimeoutException";
} catch (InvalidResponseException e) {
// Invalid response
System.err.println("Receive invalid respose");
e.printStackTrace();
return "InvalidResponseException";
} catch (NegativeResponseException e) {
// Receiving negative response (non-zero command_status)
System.err.println("Receive negative response");
e.printStackTrace();
return "NegativeResponseException";
} catch (IOException e) {
System.err.println("IO error occur");
e.printStackTrace();
}
catch (Exception e) {
System.err.println("Exeption Occur");
e.printStackTrace();
return "Eror";
}
return "Success";
}
}
Help me figure out my issue please
you have to create a global static SMPPSession variable like below.
move SmppSession object as instance variable so that the session object persists.