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.)
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.
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”
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 udp: 127.0.0.1:5060 udp: 127.94.0.1:5060 udp: 127.94.0.2:5060 udp: 192.168.43.106:5060 tcp: 127.0.0.1:5060 tcp: 127.94.0.1:5060 tcp: 127.94.0.2:5060 tcp: 192.168.43.106:5060 Aliases: tcp: 184.108.40.206.in-addr.arpa:5060 tcp: 220.127.116.11.in-addr.arpa:5060 tcp: localhost:5060 udp: 18.104.22.168.in-addr.arpa:5060 udp: 22.214.171.124.in-addr.arpa: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:127.0.0.1:5060, 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 192.168.43.166 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 192.168.43.106 in this case. To make a VoIp call, we’re going to use this command:
call new sip:192.168.43.106:5080
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.