title: pjsip receive sms
body: <p>Anyone know any good examples on how to setup a pjsip client to receive messages.
  I can send messages from the client using:</p>
  
  <pre><code>pjsua_im_send(sip_acc_id, &amp;to, NULL, &amp;msgbody, NULL, NULL);
  </code></pre>
  
  <p>to any number.</p>
  
  <p>But I have no idea what to do to receive messages into the already registered sip account.</p>
  
  <p>Any info would be greatly appreciated.</p>
  
  <p>Note: I can only use pjsip and no other library.</p>
  
  <p><strong>Edit:</strong> Some new stuff I found:</p>
  
  <p><a href="http://trac.pjsip.org/repos/ticket/1070" rel="nofollow">http://trac.pjsip.org/repos/ticket/1070</a></p>
  
  <p><a href="http://www.pjsip.org/release/0.5.4/PJSIP-Dev-Guide.pdf" rel="nofollow">http://www.pjsip.org/release/0.5.4/PJSIP-Dev-Guide.pdf</a> (however all this document says about incoming msgs is this: </p>
  
  <p><strong>16.1.2 Receiving MESSAGE</strong></p>
  
  <p>Incoming MESSAGE requests outside any dialogs will be received by application
  module.
  Incoming MESSAGE requests inside a dialog will be notified to dialog usage via
  <strong>on_tsx_state()</strong> callback of the dialog.</p>
  
  <p>which still doesn't shine much light on how to handle incoming messages.</p>
  
  <p><a href="http://www.ietf.org/rfc/rfc3261.txt" rel="nofollow">http://www.ietf.org/rfc/rfc3261.txt</a></p>
  
  <p><a href="http://trac.pjsip.org/repos/wiki/SIP_Message_Buffer_Event" rel="nofollow">http://trac.pjsip.org/repos/wiki/SIP_Message_Buffer_Event</a></p>
  
  <p><strong>Edit2:</strong> I've been told that on_pager function needs to be used for this functionality. So I tried but still no success unfortunately.</p>
  
  <p>Here is what I did:</p>
  
  <pre><code>/* Initialize application callbacks */
    app_config-&gt;cfg.cb.on_call_state = &amp;on_call_state;
    app_config-&gt;cfg.cb.on_call_media_state = &amp;on_call_media_state;
    app_config-&gt;cfg.cb.on_incoming_call = &amp;on_incoming_call;
    app_config-&gt;cfg.cb.on_reg_state = &amp;on_reg_state;
    app_config-&gt;cfg.cb.on_pager = &amp;on_pager;
  </code></pre>
  
  <p>And the on_pager implementation:</p>
  
  <pre><code>static void on_pager(pjsua_call_id call_id, const pj_str_t *from, const pj_str_t *to, const pj_str_t *contact, const pj_str_t *mime_type, const pj_str_t *body) {
  
      NSLog(@"****************  on_pager called  **********************");
      AppDelegate *app = (AppDelegate *)[AppDelegate sharedApplication];
  
      pjsua_call_info ci;
  
      pjsua_call_get_info(call_id, &amp;ci);
  
      PJ_UNUSED_ARG(call_id);
      PJ_UNUSED_ARG(to);
      PJ_UNUSED_ARG(contact);
      PJ_UNUSED_ARG(mime_type);
  
      [app ring];
  
      //PJ_LOG(3,(THIS_FILE, "MESSAGE from %.*s: %.*s (%.*s)", (int)from-&gt;slen, from-&gt;ptr, (int)text-&gt;slen, text-&gt;ptr, (int)mime_type-&gt;slen, mime_type-&gt;ptr));
  
      postMessageStateNotification(call_id, &amp;ci);
  
  }
  </code></pre>
  
  <p>I was expecting the application to call on_pager when a message is received but it didn't.
  <code>on_incoming_call</code> however, does get called.</p>