配置stun服务器实现穿墙

Turn服务器的配置流程

Webrtc是基于P2P的,在两个客户端建立连接之前需要服务器建立连接,这时两台设备一般都处于一个或者多个NAT中,那么两台设备建立连接就需要穿墙技术。

这时就用到了turn服务器,他包括stun服务器,stun服务器主要用来获得外网的地址,而turn服务器则负责在P2P连接失败时进行转发

推荐一个部署turn服务器的方式,下载地址https://github.com/coturn/coturn

 

下载完成以后进行安装,cd到下载coturn的目录下

执行./configure

make

make install

执行时会报错Libevent2 development is not installed properly

ERROR: Libevent2 development libraries are not installed properly in required location.

ERROR: may be you have just too old libevent tool - then you have to upgrade it.

See the INSTALL file.

说明你需要安装libevent,以ubuntu为例执行命令进行安装sudo apt-get install libevent-dev

如果执行成功会在conturn的bin目录下生成一些文件

 

配置iceServer

turnserver -o -a -f -v --mobility -m 10 --max-bps=100000 --min-port=32355 --max-port=65535 --user=username1:password1 --user=username2:password2 -r demo –m 10

其中username1和username2分配了两个不同的账号和密码

在服务器内的配置

webrtc的服务器一般使用SkyRTC,下载地址https://github.com/LingyuCoder/SkyRTC-demo

 

下载后按照文档进行安装和配置

配置stun需要在SkyRTC-client.js

内配置iceServers,配置的端口默认是3478,格式如下

“url“: 'stun:ip:3478'

“username”: 'username1’

“password”:’password1’

posted @ 2017-06-28 09:19  一米王子  阅读(7762)  评论(0编辑  收藏  举报