How to Make an iOS VoIP App With Pjsip: Part 2
2015-07-28 14:39
846 查看
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.
And 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 sourec 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.
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.
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:
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:
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.
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.
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:
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:
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:
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.
post, we have talked about how to compile pjsip, and run the built in demo on a real device.
And 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 sourec 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.
What’s Kamailio
Here is the definition of Kamailio from the officialwebsite:
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:
/usr/local/etc/kamailio/kamailio.cfg
You can now go ahead and start running kamailio:
/usr/local/sbin/kamailio
You’ll see output similar to the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 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: 106.43.168.192.in-addr.arpa:5060 tcp: 1.0.0.127.in-addr.arpa:5060 tcp: localhost:5060 udp: 106.43.168.192.in-addr.arpa:5060 udp: 1.0.0.127.in-addr.arpa:5060 udp: localhost: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:
make
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:
./receiver
After a bunch of messages, you’ll see something like the following:
1 2 3 | 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 |
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.
To be continued…
相关文章推荐
- iOS KVO概述(刚刚)
- iOS 发布证书申请
- iOS多线程的初步研究(三)-- NSRunLoop
- iOS协议里面可以定义成员变量和属性吗?(刚刚)
- iOS下载图片并显示进度
- iOS开发-优秀博客-实用技巧
- iOS设置导航与其标题的颜色及字体大小和系统默认TabBar的相关设置与使用方法
- iOS开发的一些奇巧淫技
- iOS地图定位使用几个小功能(刚刚)
- 【iOS发展-44】通过案例谈iOS重构:合并、格式化输出、宏观变量、使用数组来存储数据字典,而且使用plist最终的知识
- ios--c DAY_1
- Nagios 监控
- iOS调用系统发短信功能详解(刚刚)
- iOS Animation详解
- iOS开发使用代码创建一个Label控件
- ios开发—利用xcode tabbed模块快速开发标签栏应用
- iOS 数据请求 GZip数据压缩和解压缩问题
- IOS NSString比较,截取,NSLog,NSRang,isEqualToString,stringWithFormat
- iOS utf-8和 url encode
- js调用oc方法(ios自学笔记)