How to Make an iOS VoIP App With Pjsip: Part 2

Welcome to the second part of this tutorial series! In previous post, we have talked about how to compile pjsip, and run the built in demo on a real device.

After this tutorial, you’ll be able to make your 1st VoIP call via the demo we compiled before.

To actually make VoIP calls, we’re going to setup a VoIP server on your own mac. Since testing VoIP calls takes 2 devices, we’ll create a console app on the Mac to receive the phone call, and use iPhone to actually call it.

In this tutorial, you’ll learn:

  • Setting up a VoIP server to handle sip requests
  • Using PJSUA-CLI to make VoIP calls

To simplify the process so that you could start making VoIP calls immediately, we’ll just simply provide the source code of the console VoIP receiver app here. For further detail, we’ll cover it in our next tutorial.

And for the VoIP server, we’re going to use Kamailio.

(This article was written on 2014 and posted on my old blog. Most of the content should still work on latest Mac and iOS, i.e, macOS Sierra and Xcode 8.3. Please let me know if you find anything not working, thanks.)

What’s Kamailio

Here is the definition of Kamailio from the official website:

Kamailio® (former OpenSER) is an Open Source SIP Server released under GPL, able to handle thousands of call setups per second.

Among features:
asynchronous TCP, UDP and SCTP, secure communication via TLS for VoIP (voice, video); WebSocket support for WebRTC; IPv4 and IPv6; …

It can be used to build large VoIP servicing platforms or to scale up SIP-to-PSTN gateways, PBX systems or media servers like Asterisk™, FreeSWITCH™ or SEMS…

So, simply put, Kamailio is a great open source VoIP server. Once we successfully deployed and configured Kamailio, our VoIP clients can make VoIP calls to each other via it.

Download and install

To simplify the process, we’ll use Mac directly as the server, instead of a dedicated Linux server like CentOS.

So let’s download the latest source of kamailio from its official website. As the time of writing, it’s 4.1.4.

After unzipping the downloaded source, enter the directory and run the following command to compile and install it:

$ ./make_and_install compile && ./make_and_install install "standard"

It will be installed to /usr/local automatically. To be specific, the binary file will be installed to “/usr/local/sbin/kamailio”

Configure kamailio

Beore starting kamailio service, you need to create the kamailio.cfg file. You could download a sample configuration file here, and save it to:


You can now go ahead and start running kamailio:


You’ll see output similar to the following:

loading modules under /usr/local/lib64/kamailio/modules/
Listening on
 tcp: localhost:5060
 udp: localhost:5060

This means your kamailio has been successfully started, and it’s listerning on port 5060. You can now connect your VoIP clients to it and start making VoIP calls.

Create a console VoIP receiver app on your Mac

In order to enable you to make VoIP calls sooner, we’re not going to explain the details for now (of course, if you’re interested, you could try to understand the code yourself). We’ll cover the details in the next tutorial.

Download the source code of the VoIP receiver app I wrote here.

After unzip the file, go into the directory and compile it:


You’ll get the executable receiver in the folder.

Actually make VoIP calls

Great, now both the clients and the server are ready, let’s make some VoIP calls.

First of all, let’s launch the receiver app on Mac:


After a bunch of messages, you’ll see something like the following:

16:37:22.631 pjsua_acc.c ....SIP outbound status for acc 0 is not active
16:37:22.631 pjsua_acc.c ....sip:receiver@localhost: registration success, status=200 (OK), will re-register in 300 seconds
16:37:22.631 pjsua_acc.c ....Keep-alive timer started for acc 0, destination:, interval:15s

This means the receiver@localhost has been successfully registered on our SIP server.

Next, open the demo app we compiled previously (it’s ipjsua if you didn’t change the name), check the text on the bottom of the screen, and then telnet to it from your mac based on the info:

telnet 2323

Finally, let’s send the command to actually make our 1st VoIP call. Since the receiver is listening on port 5080, and the IP address of the Mac is in this case. To make a VoIp call, we’re going to use this command:

call new sip:

After 1~2 seconds, your iPhone and your Mac will establish the VoIP call, you can then hear the voice from iPhone on Your mac and vice versa.

To be continued…

One thought on “How to Make an iOS VoIP App With Pjsip: Part 2

  1. Thanks for the great info.
    I’m having an issue getting Kamailio installed on my Mac. I have experience with Terminal but am far from an expert user. I’m sure I’m missing something obvious.
    – I downloaded 5.0.1_src.tar.gz and unzipped it.
    – Opened Terminal, cd to kamailio-5.0.1 directory
    – Run ./make_and_install compile && ./make_and_install install “standard”, Which errors out because ‘no such file’. I see the file inside the src/core folder.
    – If I run src/core/make_and_install compile && src/core/make_and_install install “standard”, it COMPILES but getting errors. Inside make_and_install_output.txt it says its missing files like: modules.lst & config.mak, which both exist in the src folder. What I am I missing?



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s