Question

I am using JSMPP from Google to receive SMS messages from SMS Service Centre. Sometimes, my program stops receiving SMS from SMSC, I have to close the program and Re-Open the program. Then Queued SMSes from SMSC starts receive. This happens after some time, like after 7 or 8 hours. Here is the code I'v used

SMPP Init Code

l.info("SMPP Initialization");

SMPPSession s = new SMPPSession();

s.setMessageReceiverListener(new Receive(s));


s.connectAndBind(Settings.smsc_host,Settings.smsc_port, BindType.BIND_TRX,
Settings.smsc_user, Settings.smsc_password,Settings.smsc_msg_setting, TypeOfNumber.UNKNOWN,
NumberingPlanIndicator.UNKNOWN, null, Settings.smsc_timeout);

ProcessSMS.s = s;

l.info("SMPP Initialization Success");

SMS Receive Code

package sms;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.apache.log4j.Logger;
import org.jsmpp.bean.AlertNotification;
import org.jsmpp.bean.DataSm;
import org.jsmpp.bean.DeliverSm;
import org.jsmpp.bean.MessageType;
import org.jsmpp.extra.ProcessRequestException;
import org.jsmpp.session.DataSmResult;
import org.jsmpp.session.MessageReceiverListener;
import org.jsmpp.session.Session;

import processor.ProcessSMS;

public class Receive implements MessageReceiverListener {

private static final ExecutorService pool = Executors.newFixedThreadPool(10);

private static final Logger l = Logger.getLogger(Receive.class);

private Thread thread;

public Receive(){
super();
}

public Receive(Session s){
this();
}

@Override
public DataSmResult onAcceptDataSm(DataSm arg0, Session arg1)
throws ProcessRequestException {

return null;
}

@Override
public void onAcceptAlertNotification(AlertNotification arg0) {


}

@Override
public void onAcceptDeliverSm(DeliverSm arg0)
throws ProcessRequestException {

l.info("Received SMS " + arg0);



if(MessageType.SMSC_DEL_RECEIPT.containedIn(arg0.getEsmClass())){

}else{
pool.submit(new ProcessSMS(arg0));
//thread = new Thread(new ProcessSMS(arg0));
//thread.start();
}

}

}

And here is the state change class

package sms;

import java.io.IOException;

import global.Shared;
import log.SMSCStateLogger;

import org.jsmpp.bean.BindType;
import org.jsmpp.bean.NumberingPlanIndicator;
import org.jsmpp.bean.TypeOfNumber;
import org.jsmpp.extra.SessionState;
import org.jsmpp.session.SMPPSession;
import org.jsmpp.session.Session;
import org.jsmpp.session.SessionStateListener;

import processor.ProcessSMS;
import settings.Settings;

public class StateChange implements SessionStateListener{

private static SMSCStateLogger l  = new SMSCStateLogger(StateChange.class);

private Session s;

@Override
public void onStateChange(SessionState arg0, SessionState arg1, Object arg2) {
//arg0 = new State
//arg1 = old State

if(!arg0.isBound() && arg1.isBound()){
int con = Shared.getNextReConnectInterval();
l.info("State changed from " + arg1 + " to " + arg0 + " on " + arg2);

while(true){
l.info("Re Connection in " + con + " ms");

try{
Thread.sleep(con);
}catch(InterruptedException iex){
l.fatal("Re Connection failed due to exception " + iex);
break;
}

s = new SMPPSession();

((SMPPSession) s).setMessageReceiverListener(new Receive(s));
s.addSessionStateListener(new StateChange());

try{

((SMPPSession) s).connectAndBind(Settings.smsc_host,Settings.smsc_port,  BindType.BIND_TRX,
Settings.smsc_user, Settings.smsc_password,Settings.smsc_msg_setting, TypeOfNumber.UNKNOWN,
NumberingPlanIndicator.UNKNOWN, null, Settings.smsc_timeout);

}catch(IOException ioex){
l.fatal("Connection failed due to " + ioex.getMessage());
}

ProcessSMS.s = (SMPPSession) s;

l.info("Re Connection success");

break;


}
}
}

}

Does anybody have an idea what is going on ?

Was it helpful?

Solution

Updated the JSMPP API from https://github.com/uudashr/jsmpp.

Download the source with git run mvn install to create the jar archive.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top