/protocols/smpp/docs/UserGuide.html

http://mobicents.googlecode.com/ · HTML · 280 lines · 233 code · 47 blank · 0 comment · 0 complexity · b5b5e303c61d5f497f7aede7096f6c92 MD5 · raw file

  1. <html>
  2. <head>
  3. <link rel="stylesheet" href="UserGuide.css" type="text/css" />
  4. <title>Java SMPP API User's Guide</title>
  5. </head>
  6. <body>
  7. <div class="smppapiDoc">
  8. <h1>Java SMPP API User's Guide</h1>
  9. <h2>Document status</h2>
  10. <p>
  11. This document is brief and extremely rough-and-ready. Feedback and criticism should be posted to the relevant discussion forums on <a href="http://www.sf.net/projects/smppapi/">Sourceforge</a>.
  12. </p>
  13. <p>
  14. The latest version of this document is always available at <a href="http://smppapi.sourceforge.net/user-guide/">http://smppapi.sourceforge.net/user-guide/</a>.
  15. </p>
  16. <h2>Introduction</h2>
  17. <p>
  18. This guide describes the use of the <b>Java SMPP API (<i>smppapi</i>)</b> in an application. The project resides on the web at <a href="http://www.sf.net/projects/smppapi">http://www.sf.net/projects/smppapi</a>.
  19. </p>
  20. <p>
  21. This guide is meant only as an introduction to the functionality provided by the API. Developer's should refer to the <a href="apiDocs/index.html">API documentation</a> for a comprehensive description of the interfaces available.
  22. </p>
  23. <h3>License</h3>
  24. <p>The smppapi is released under the GNU Lesser GPL (LGPL). The text of the LGPL should be in the LICENSE file in the top-level of the smppapi distribution and can also be <a href="http://www.opensource.org/">the Open Source Initiative</a>.
  25. </p>
  26. <h2>Interface version</h2>
  27. <p>
  28. The API supports versions 3.3 and 3.4 of the SMPP specification.
  29. </p>
  30. <h2>Packages</h2>
  31. <p>
  32. The smppapi classes are packaged in (and under) the <code>ie.omk.smpp namespace.</code> Top-level classes (such as <b><code><a href="apiDocs/ie/omk/smpp/Connection.html">Connection</a></b>) are in the <code>ie.omk.smpp</code> package. SMPP message primitives (requests and responses) are in the <code>ie.omk.smpp.message</code> package. Classes which handle network connectivity (eg <b><code><a href="apiDocs/ie/omk/smpp/net/TcpLink.html">TcpLink</a></code></b>) reside in the <code>ie.omk.smpp.net</code> package. There are also some utility classes in <code>ie.omk.smpp.util</code> package.
  33. <h2>Establishing the network link</h2>
  34. <p>
  35. The physical connection between an SMPP application (<i>ESME</i>) and the <i>SMSC</i> is defined by the <code>SmscLink</code> abstract class. Specific network implementations extend this class to allow the API to communicate with the SMSC over any Java-supported network protocol. The smppapi currently provides two concrete SmscLink implementations:
  36. <ul>
  37. <li><code>TcpLink</code>. This allows an ESME to communicate with the SMSC
  38. over the Internet-standard TCP/IP protocol.
  39. <li><code>StreamLink</code>. This class is mainly provided for debugging purposes.
  40. It allows the ESME to provide any Java input stream and output stream for the
  41. smppapi to use for i/o.
  42. </ul>
  43. </p>
  44. <h3>Using <code>TcpLink</code></h3>
  45. <p>
  46. A TCP/IP link can be established to the SMSC in two ways. In the first case, the developer relies on the API to open the underlying socket to the remote system. In the second, the socket connection is already established.
  47. </p>
  48. <p>
  49. <u>Case 1</u>:
  50. <div class="codeblock">
  51. try {
  52. // First get the java.net.InetAddress for the SMSC:
  53. InetAddress smscAddr = InetAddress.getByName("smsc.domain.com");
  54. // Use port 5432
  55. TcpLink smscLink = new TcpLink(smscAddr, 5432);
  56. // Open the connection (not required)..
  57. smscLink.open();
  58. } catch(java.net.UnknownHostException ux) {
  59. System.err.println("SMPPAPI: " + ux.getMessage());
  60. }
  61. </div>
  62. </p>
  63. <p>
  64. <u>Case 2</u>:
  65. <div class="codeblock">
  66. try {
  67. // Open the socket..
  68. Socket s = new Socket("smsc.domain.com", 5432);
  69. // Create the TCP link..
  70. TcpLink smscLink = new TcpLink(s);
  71. } catch (java.net.UnknownHostException x) {
  72. ...
  73. } catch (java.io.IOException x) {
  74. ...
  75. }
  76. </div>
  77. </p>
  78. <h3>Using <code>StreamLink</code></h3>
  79. <p>
  80. The <code>StreamLink</code> class is provided mainly for debugging purposes. It's primary purpose is to read SMPP packets from a binary file. However, it is possible to pass any Java <code>InputStream</code> and <code>OutputStream</code> to the <code>StreamLink</code> constructor. For instance, if a file 'responses.bin' exists that contains a set of response messages that a developer wishes to test against, she may do so like this:
  81. <div class="codeblock">
  82. FileInputStream fin = new FileInputStream("responses.bin");
  83. FileOutputStream fout = new FileOutputStream("/dev/null");
  84. StreamLink link = new StreamLink(fin, fout);
  85. Connection tran = new Connection(link);
  86. link.bind(Connection.TRANSMITTER, ...);
  87. // run tests...
  88. </div>
  89. Obviously, the responses should match whatever requests are sent.
  90. </p>
  91. <h2>Connections, Transmitters, Receivers and Transceivers.</h2>
  92. <p>
  93. SMPP defines three modes of operation for an ESME; transmitter, receiver and transceiver. An ESME must select one of these modes of operation when it <i>binds</i> to the SMSC. In transmitter mode, an ESME is capable of submitting messages to the SMSC, querying the status of messages and system parameters but it is not able to receive short messages from the SMSC. To be capable of receiving delivery of short messages, an ESME must also bind as a receiver. In receiver mode, the SMSC will send <code>deliver_sm</code> packets to the ESME. In receiver mode, however, all the operations available in transmitter mode are disabled. A receiver and transmitter type connection require two separate network links. That is, a receiver and transmitter connection cannot share the same TCP network link.
  94. <p>SMPP version 3.4 introduced the transceiver type of connection. When an ESME binds to the SMSC in transceiver mode, it is similar to having a transmitter and receiver connection over the same network link. However, SMPP 3.4 also altered other aspects of the protocol, so the transceiver connection cannot be considered identical to a transmitter and receiver rolled into one.</p>
  95. <p>To bind to the SMSC as a particular type, the calling application should pass the appropriate enumeration value into the
  96. <code>Connection.bind</code> method. Valid enumeration values are:
  97. <ul>
  98. <li><code>Connection.TRANSMITTER</code>
  99. <li><code>Connection.RECEIVER</code>
  100. <li><code>Connection.TRANSCEIVER</code>
  101. </ul>
  102. Note that the Connection object must have it's internal version set appropriately to support a transceiver connection. See the <code>Connection.setVersion</code> method.
  103. <h2>Synchronous versus Asynchronous communication.</h2>
  104. <p>
  105. The smppapi supports both synchronous and asynchronous communication. <b>Synchronous</b> communication is the default. This means that when a request is sent to the SMSC, the API <i>blocks</i> until the response is received from the SMSC. In asynchronous communication, the API returns immediately after sending a request and notifies your application once the response is received from the SMSC. More than one <i>observer</i> can be notified of an incoming SMPP packet from the SMSC.
  106. </p>
  107. <p>
  108. As synchronous communication is the default, no special action needs to be taken when using the <code>Connection</code> class. Its use is simply:
  109. <div class="codeblock">
  110. try {
  111. Connection trans = new Connection(smscLink);
  112. .
  113. .
  114. SMPPResponse resp = trans.sendRequest(req);
  115. if (resp.getCommandStatus() != 0) {
  116. ...
  117. }
  118. } catch (SMPPException x) {
  119. ...
  120. }
  121. </div>
  122. </p>
  123. <p>
  124. To create a <code>Connection</code> that uses asynchronous communication, an implementation of the <code>ie.omk.smpp.event.ConnectionObserver</code> interface is needed. The connection observer will receive updates from the API for various internal API events, including packet reception.
  125. <div class="codeblock">
  126. public class MyListener implements ie.omk.smpp.event.ConnectionObserver {
  127. public void packetReceived(Connection source, SMPPPacket packet) {
  128. // Process received packet
  129. ...
  130. }
  131. // Method called for API events other than packet reception.
  132. public void update(Connection source, SMPPEvent event) {
  133. // process event..
  134. ...
  135. }
  136. }
  137. </div>
  138. </p>
  139. <p>
  140. This observer object must now be registered with the <code>Connection</code> object so that it can receive updates.
  141. <div class="codeblock">
  142. // Create a listener object
  143. MyListener myListener = new MyListener();
  144. // Create an asynchronous transmitter..
  145. Connection trans = new Connection(smscLink, true);
  146. // Register the listener..
  147. trans.addObserver(myListener);
  148. </div>
  149. </p>
  150. <h2>Synchronous communication as a receiver</h2>
  151. <p>
  152. While it is possible to use synchronous communication with a receiver connection, it is generally more useful to use asynchronous communication when binding as a receiver. This is because the only thing a receiver application does once it binds is wait for the SMSC to deliver messages to it. Therefore, it makes sense for a receiver application to bind and then let the smppapi wait for incoming messages. Once received, the application will be passed an <code>SMPPEvent</code> as described above.
  153. </p>
  154. <p>
  155. To use synchronous communication while bound as a receiver, have a look at the <code><a href="apiDocs/ie/omk/smpp/Connection.html#readNextPacket(long)">Connection.readNextPacket</a></code> method.
  156. <h2>Binding to the SMSC</h2>
  157. <p>
  158. To bind to the SMSC, call the <code>Connection.bind</code> method with appropriate arguments. For example:
  159. </p>
  160. <p>
  161. <u>Binding to the SMSC as a transmitter</u>:
  162. <div class="codeblock">
  163. Connection c = new Connection(smscLink);
  164. /*
  165. * Bind to the SMSC...use the default routing information
  166. * configured at the SMSC..
  167. */
  168. BindResp r = c.bind(Connection.TRANSMITTER, "sysID", "secret", "sysType", null);
  169. if (r.getCommandStatus() != 0) {
  170. ...
  171. }
  172. ...
  173. </div>
  174. </p>
  175. <h2>Handling an SMPPEvent</h2>
  176. <p>
  177. As already discussed, when using asynchronous communication, the smppapi will notify an observer of an incoming SMPP packet from the SMSC with a call to it's <code>packetReceived</code> method. <u>It is very important to keep thread-safety in mind when writing your event handler methods</u> as the smppapi makes no guarantees that it will dispatch only one event at a time. An example SMPP event handler follows:
  178. <div class="codeblock">
  179. public class MyListener implements ie.omk.smpp.event.ConnectionObserver {
  180. public void packetReceived(Connection source, SMPPPacket pak) {
  181. try {
  182. switch (pak.getCommandID()) {
  183. case SMPPPacket.ESME_BNDTRN_RESP:
  184. if (pak.getCommandStatus() == 0) {
  185. // successfully bound...
  186. this.submitMessages();
  187. } else {
  188. // handle error...
  189. }
  190. break;
  191. case SMPPPacket.ESME_SUB_SM_RESP:
  192. ...
  193. break;
  194. case SMPPPacket.GENERIC_NAK:
  195. ..
  196. break;
  197. } catch (SMPPException x) {
  198. // handle exception...
  199. }
  200. }
  201. public void update(Connection source, SMPPEvent event) {
  202. // called for control events..
  203. switch (event.getType()) {
  204. case SMPPEvent.RECEIVER_EXCEPTION:
  205. // an exception occurred in the receiver thread..
  206. break;
  207. case SMPPEvent.RECEIVER_EXIT:
  208. // the receiver thread has just died.
  209. break;
  210. // see the event framework for further events.
  211. }
  212. }
  213. }
  214. }
  215. </div>
  216. </p>
  217. <h2>Automatic responses.</h2>
  218. <p>
  219. In certain cases the SMSC may send request packets to an ESME. The only two cases in SMPP version 3.3 are when the SMSC is delivering short messages to an ESME (only relevant to a receiver) and when the SMSC sends an <code>EnquireLink</code> request (both receiver and transmitter). The <code>Connection</code> can be set up to automatically respond to these messages. Thus, so long as the ESME is 'alive', if the SMSC sends an <code>EnquireLink</code> request, the smppapi will respond immediately with <code>EnquireLinkResp</code>. The request packet will still be passed to the application by the smppapi in the normal manner.
  220. </p>
  221. <p>
  222. By default, automatically acknowledging links is <b>enabled</b> while automatically acknowledging messages is <b>disabled</b>. To change these settings, use the <code>Connection.autoAckLink</code> and <code>Connection.autoAckMessages</code> methods.
  223. </p>
  224. <h2>Appendix A: Glossary.</h2>
  225. <table cols="2">
  226. <tr><td>SMPP</td><td>Short Message Peer to Peer</td></tr>
  227. <tr><td>SMSC or SC</td><td>Short Message Service Centre</td></tr>
  228. <tr><td>ESME or SME</td><td>(External) Short Message Entity</td></tr>
  229. </table>
  230. <div class="copyright">&copy; Copyright 1998 - 2007 by Oran Kelly. <a href="http://smppapi.sourceforge.net/">smppapi</a></div>
  231. </div>
  232. </body>
  233. </html>