OpenSmpp / opensmpp

OpenSmpp - Java library implementing the SMPP protocol, and allowing development of External Short Message Entities (ESMEs) and more.
http://opensmpp.org/
Other
188 stars 170 forks source link

Problem when using the deliver method to send a short messege #22

Closed sadok1992 closed 7 years ago

sadok1992 commented 7 years ago

Hello, I use opensmpp and try the submit method (Submit_SM) and it work fine. But later i discover that i must use the deliver method (Deliver_SM) in order to use the listener side of the ESME and receive the message from the SMSC. Here is my code the bind work fine but the response from the deliver method is always null. Please if anyone can help me or at least give me a little example whith the deliver method PS: I use the synchronous mode.

import org.smpp.pdu.BindRequest import org.smpp.pdu.BindResponse import org.smpp.pdu.BindTransciever import org.smpp.pdu.BindTransmitter import org.smpp.pdu.BindReceiver import org.smpp.TCPIPConnection import org.smpp.Session import org.smpp.test.SMPPTest.SMPPTestPDUEventListener import org.smpp.pdu.AddressRange import org.smpp.Data import org.smpp.pdu.UnbindResp import org.smpp.pdu.DeliverSM import org.smpp.pdu.DataSM import org.smpp.pdu.DeliverSMResp import org.smpp.pdu.DataSMResp import org.smpp.pdu.PDU import org.smpp.pdu.Request import org.smpp.pdu.Response import org.smpp.ServerPDUEvent import org.smpp.pdu.Address import org.smpp.pdu.EnquireLink import org.smpp.pdu.EnquireLinkResp

Session session = null; def bound = false boolean asynchronous = false; String bindOption = "tr"; String systemType = ""; String serviceType = ""; Address sourceAddress = new Address() Address destAddress = new Address() byte replaceIfPresentFlag = 0; String shortMessage = ""; // the message to send String scheduleDeliveryTime = ""; String validityPeriod = "" // default estimated validity default period byte esmClass = 0; byte protocolId = 0; byte priorityFlag = 0; byte registeredDelivery = 0; byte dataCoding = 0; byte smDefaultMsgId = 0; String messageId = ""; long receiveTimeout = Data.RECEIVE_BLOCKING; AddressRange addressRange = new AddressRange(); SMPPTestPDUEventListener pduListener = null;

    println "begin binding operation..."
    try {

        // test if communication is already established
        if (bound) {
            System.out.println("Already bound, unbind first.");
            return;
        }

        BindRequest request = null;
        BindResponse response = null;
        // type of the session
        String syncMode = (asynchronous ? "a" : "s");

        // input values

        if (bindOption.compareToIgnoreCase("t") == 0) {
            request = new BindTransmitter();
        } else if (bindOption.compareToIgnoreCase("r") == 0) {
            request = new BindReceiver();
        } else if (bindOption.compareToIgnoreCase("tr") == 0) {
            request = new BindTransciever();
        }

        ipAddress = "xxx.xxx.xx.xx";
        port = yyyy;

        println "syncMode == "+syncMode
        TCPIPConnection connection = new TCPIPConnection(ipAddress, port);
        connection.setReceiveTimeout(20 * 1000);
        session = new Session(connection);

        systemId = "nnnnnn"
        password = "nnnnnn"

        // set values
        request.setSystemId(systemId);
        request.setPassword(password);
        request.setSystemType(systemType);
        request.setInterfaceVersion((byte) 0x34);
        request.setAddressRange(addressRange);

        // send the request
        System.out.println("Bind request " + request.debugString());
        if (asynchronous) {
            pduListener = new SMPPTestPDUEventListener(session);
            response = session.bind(request, pduListener);
        } else {
            response = session.bind(request);
        }
        System.out.println("Bind response " + response.debugString());
        println "response.getCommandStatus() === "+response.getCommandStatus()
        if (response.getCommandStatus() == Data.ESME_ROK) {
            bound = true;
            println "SMSC is bound succesfuuly with the ESME"
        }

    } catch (Exception e) {
        //event.write(e, "");
        //debug.write("Bind operation failed. " + e);
        System.out.println("Bind operation failed. " + e);
    } finally {
        //session.unbind()
        //connection.close()
    }

    println "enquire data ... "
    try {
        final EnquireLink request = new EnquireLink();
        System.out.println("Enquire Link request " + request.debugString());
        final EnquireLinkResp response = session.enquireLink(request);
        System.out.println("Enquire Link response " + response.debugString());
    } catch (Throwable e) {
        e.printStackTrace();
    }

try {
    DeliverSM request = new DeliverSM();
    DeliverSMResp response;

            // input values
            serviceType = ""
            sourceAddress.setNpi((byte)1)
    sourceAddress.setTon((byte)1)
    sourceAddress.setAddress("4123601", Data.SM_ADDR_LEN)
            destAddress.setNpi((byte)1)
    destAddress.setTon((byte)1)
    destAddress.setAddress("0022233411686", Data.SM_ADDR_LEN)
            esmClass = 0
            registeredDelivery = 0;
            dataCoding = 0;

           // set values
    request.setServiceType(serviceType);
            request.setSequenceNumber(1)
    request.setSourceAddr(sourceAddress);
    request.setDestAddr(destAddress);
    request.setEsmClass(esmClass);
    request.setRegisteredDelivery(registeredDelivery);
    request.setDataCoding(dataCoding);
            request.setProtocolId(protocolId)
            request.setPriorityFlag(priorityFlag);
            request.setShortMessage("Hello world",Data.ENC_ASCII);

    // send the request
    System.out.println("Data request " + request.debugString());
    if (asynchronous) {
        session.data(request);
    } else {
        response = session.deliver(request); // here the problem , the response is always null
        System.out.println("Data response " + response.debugString());
        messageId = response.getMessageId();
    }

} catch (Exception e) {
        System.out.println("Data operation failed. " + e);
    }
finally {
       session.unbind()
}