Session
provides all methods necessary for communication with SMSC using SMPP protocol, i.e. methods for sending PDUs as defined in SMPP specification as well as receiving responses for sent PDUs and waiting for PDUs whose sending was initiated by SMSC.Session
represents one connection of ESME to a SMSC. Multiple connections can be established using multiple Sessions
. Session
uses Connection
object which is instantiated outside of the Session
. This way is the Session
made independent on the communication protocol and Session
's code isn't populated by protocol dependent initialisation.
Code example of binding, sending one message and unbinding:
Note that the cycle bind - send PDU's - unbind can be called several times for once created session.Connection conn = new TCPIPConnection("123.123.123.123", 6543); Session session = new Session(conn); BindRequest breq = new BindTransmitter(); breq.setSystemId("MYNAME"); breq.setPassword("my_pswdx"); Response resp = session.bind(breq); if (resp.getCommandStatus() == Data.ESME_ROK) { SubmitSM msg = new SubmitSM(); msg.setSourceAddr("3538998765432"); msg.setDestAddr("3538619283746"); msg.setShortMessage("Hello, world!"); resp = session.submit(msg); if (resp.getCommandStatus() == Data.ESME_ROK) { System.out.println("Message submitted. Status=" + resp.getCommandStatus()); } else { System.out.println("Message submission failed. Status=" + resp.getCommandStatus()); } session.unbind(); } else { System.out.println("Couldn't bind. Status=" + resp.getCommandStatus()); }
Particular methods for sending PDUs to SMSC return responses to the sent PDUs. They return null if no response is received in time specified by the receive timeout in receiver. This means that the methods wait for response corresponding to the request. The corresponding response is recognized using sequence number of the sent PDU and a corresponding response command id.
The session can work in assynchronous manner, i.e. it doesn't wait for response for the sent request, instead all responses are handled by instance of callback class ServerPDUEventListener
whenever they are received.
The Session
class checks if operations invoked are valid in the current state of the session. If not, then such operation throws WrongSessionStateException
expcetion. For example it's incorrect to try to submit a message if the session is bound as receiver. The checking if the operation is valid in the current state of session is turned off by default.
@author Logica Mobile Networks SMPP Open Source Team
@version $Revision: 1.4 $
@see Connection
@see Transmitter
@see Receiver
@see ServerPDUEventListener
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|