Version 4 (modified by ming, 10 years ago) (diff)


Getting Started

Building PJSUA2

The PJSUA2 C++ library will be built by default by PJSIP build system.

Building Python and Java SWIG Modules

The SWIG modules for Python and Java are built by invoking make and make install manually from pjsip-apps/src/swig directory. The make install will install the Python SWIG module to user's site-packages directory.


  1. JDK.
  2. Python, version 2.7 or above is required. For Linux/UNIX, you will also need Python developent package (called python-devel (e.g. on Fedora) or python2.7-dev (e.g. on Ubuntu)). For Windows, you will need MinGW and Python SDK such as ActivePython-2.7.5 from ActiveState.

Testing The Installation

To test the installation, simply run python and import pjsua2 module:

$ python
> import pjsua2
> ^Z

Using in C++ Application

As mentioned in previous chapter, a C++ application can use pjsua2 natively, while at the same time still has access to the lower level objects and the ability to extend the libraries if it needs to. Using the API will be exactly the same as the API reference that is written in this book.

Here is a sample complete C++ application to give you some idea about the API. The snippet below initializes the library and creates an account that registers to our SIP server.

#include <pjsua2.hpp>
#include <iostream>
using namespace pj;
// Subclass to extend the Account and get notifications etc.
class MyAccount : public Account {
    virtual void onRegState(OnRegStateParam &prm) {
        AccountInfo ai = getInfo();
        std::cout << (ai.regIsActive? "*** Register:" : "*** Unregister:")
                  << " code=" << prm.code << std::endl;
int main()
    Endpoint ep;
    // Initialize endpoint
    EpConfig ep_cfg;
    ep.libInit( ep_cfg );
    // Create SIP transport. Error handling sample is shown
    TransportConfig tcfg;
    tcfg.port = 5060;
    try {
        ep.transportCreate(PJSIP_TRANSPORT_UDP, tcfg);
    } catch (Error &err) {
        std::cout << << std::endl;
        return 1;
    // Start the library (worker threads etc)
    std::cout << "*** PJSUA2 STARTED ***" << std::endl;
    // Configure an AccountConfig
    AccountConfig acfg;
    acfg.idUri = "";
    acfg.regConfig.registrarUri = "";
    AuthCredInfo cred("digest", "*", "test", 0, "secret");
    acfg.sipConfig.authCreds.push_back( cred );
    // Create the account
    MyAccount *acc = new MyAccount;
    // Here we don't have anything else to do..
    // Delete the account. This will unregister from server
    delete acc;
    // This will implicitly shutdown the library
    return 0;

Using in Python Application

Using in Java Application

import org.pjsip.pjsua2.*;
class MyAccount extends Account {
  public void onRegState(OnRegStateParam prm) {
      System.out.println("*** On registration state: " + prm.getCode() + prm.getReason());
public class test {
  static {
      System.out.println("Library loaded");
  public static void main(String argv[]) {
      try {
          // Create endpoint
          Endpoint ep = new Endpoint();
          // Initialize endpoint
          EpConfig epConfig = new EpConfig();
          ep.libInit( epConfig );
          // Create SIP transport. Error handling sample is shown
          TransportConfig sipTpConfig = new TransportConfig();
          ep.transportCreate(pjsip_transport_type_e.PJSIP_TRANSPORT_UDP, sipTpConfig);
          // Start the library
          AccountConfig acfg = new AccountConfig();
          AuthCredInfo cred = new AuthCredInfo("digest", "*", "test", 0, "secret");
          acfg.getSipConfig().getAuthCreds().add( cred );
          // Create the account
          MyAccount acc = new MyAccount();
          // Here we don't have anything else to do..
          /* Explicitly delete the account.
           * This is to avoid GC to delete the endpoint first before deleting
           * the account.
          // Explicitly destroy and delete endpoint
      } catch (Exception e) {