rfc5766-turn-server是谷歌推荐的turn开源项目,经常作WebRTC的服务器端使用。
编译环境搭建
vagran t
Windows用户要想在Windows下编译rfc5766-turn-server的话,需安装虚拟机,我推荐程序员专用的虚拟机——vagran t,Linux用户请忽略。其配置文件如下:
vagran tfile
# -*- mode: ruby -*- # vi: set ft=ruby : vagran tFILE_API_VERSION = "2" vagran t.configure(vagran tFILE_API_VERSION) do |config| config.vm.box = "hashicorp/precise64" config.vm.box_url = "virtualbox.box" config.vm.provider "virtualbox" do |vb| vb.memory = 2048 vb.cpus = 2 end end
使用命令行启动它:
vagran t up vagran t ssh
安装编译工具链
sudo apt-get install build-essential
确认安装成功:
vagran t@precise64:~$ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubu ntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages =c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-incl uded-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-li bstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-pl ugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic - -enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --targ et=x86_64-linux-gnu Thread model: posix gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) vagran t@precise64:~$ make -v GNU Make 3.81 Copyright (C) 2006 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. This program built for x86_64-pc-linux-gnu vagran t@precise64:~$
安装依赖项
sudo apt-get install libssl-dev sudo apt-get install libevent-dev sudo apt-get install libpq-dev sudo apt-get install mysql-client sudo apt-get install libmysqlclient-dev sudo apt-get install libhiredis-dev
其中SQL相关的依赖项可能会失败,不过这也没什么大不了的,SQL库是为了支持更多用户而准备的,如果你不是生产环境的话,忽略也行。
检出代码
在vagran tfile的同一目录检出https://code.google.com/p/rfc5766-turn-server/source/checkout 到任意目录,我检出到了stun,下文脚本请注意自行对号入座。
cd进去
vagran t@precise64:~$ cd /vagran t vagran t@precise64:/vagran t$ ls down.cmd stun up.cmd vagran tfile vagran t@precise64:/vagran t$ cd stun vagran t@precise64:/vagran t/stun$ ls AUTHORS examples LICENSE.OpenSSL NOTE rpm bin include Makefile postinstall.txt src build INSTALL Makefile.in README.turnadmin STATUS ChangeLog lib make-man.sh README.turnserver TODO configure LICENSE man README.turnutils turndb vagran t@precise64:/vagran t/stun$
开始编译
生成makefile文件,编译,安装
./configure make sudo make install
测试
试试看是否编译成功,先看看turnserver支持哪些功能
turnserver -h > help.txt
0: log file opened: /var/tmp/turn_1313_2014-11-04.log 0: RFC 3489/5389/5766/5780/6062/6156 STUN/TURN Server Version Citrix-3.2.4.6 'Marshal West' 0: Max number of open files/sockets allowed for this process: 4096 0: Due to the open files/sockets limitation, max supported number of TURN Sessions possible is: 2000 (approximately) 0: ==== Show him the instruments, Practical Frost: ==== 0: TLS supported 0: DTLS supported 0: Redis supported 0: PostgreSQL is not supported 0: MySQL is not supported 0: OpenSSL compile-time version 0x1000100f: fresh enough 0: Default Net Engine version: 2 (UDP thread per network endpoint) ===================================================== Usage: turnserver [options] Options: -d, --listening-device <device-name> Listener interface device (NOT RECOMMENDED. Optional, Linux only). -p, --listening-port <port> TURN listener port (Default: 3478). Note: actually, TLS & DTLS sessions can connect to the "plain" TCP & UDP port(s), too, if allowed by configuration. 省略……
支持协议
测试各基础协议是否支持
$ cd examples vagran t@precise64:/vagran t/stun/examples$ ./scripts/rfc5769.sh RFC 5769 message fingerprint test(0) result: success RFC 5769 simple request short-term credentials and integrity test result: succes s RFC 5769 NEGATIVE fingerprint test(0) result: success RFC 5769 message structure, long-term credentials and integrity test result: suc cess RFC 5769 message encoding test result: success RFC 5769 NEGATIVE long-term credentials test result: success RFC 5769 message fingerprint test(1) result: success RFC 5769 IPv4 response short-term credentials and integrity test result: success RFC 5769 NEGATIVE fingerprint test(1) result: success RFC 5769 IPv4 encoding result: success RFC 5769 message fingerprint test(2) result: success RFC 5769 IPv6 response short-term credentials and integrity test result: success RFC 5769 NEGATIVE fingerprint test(2) result: success RFC 5769 IPv6 encoding result: success vagran t@precise64:/vagran t/stun/examples$
TURN测试
先安装screen
sudo apt-get install screen
这样我们就能在一个终端里运行多个窗口了,使用快捷键Ctrl+a+c新建一个窗口,通过执行命令
./scripts/basic/relay.sh
把TURN服务器运行起来:
然后执行命令:
./scripts/basic/udp_c2c_client.sh
把客户端跑起来,可以看到它在通过中转服务器自己给自己发数据:
通过Ctrl+a+n来切回服务器的窗口,观察到它的确在收发数据:
至此,说明一切完全正常。
Reference
http://www.cnblogs.com/Haijunzhu/p/3833350.html
http://www.cnblogs.com/mchina/archive/2013/01/30/2880680.html
https://code.google.com/p/rfc5766-turn-server/
博主您好,我使用了和你相似的操作,但是我这边的收发只能开启一次(收到信息后立即中断,再次收发需要再次连接),这是怎么回事呢?