Implementing our own STUN/TURN server for WebRTC Application

匆匆过客 提交于 2019-11-26 12:58:34

问题


I am working on a webrtc application and have to implement following TURN server.

https://code.google.com/p/rfc5766-turn-server/

I am following this tutorial.

http://www.dialogic.com/den/developer_forums/f/71/t/10238.aspx

and it says to reference the TURN server as follows, in javascript code where RTCPeerConnection is created.

var pc_config = {\"iceServers\": [{\"url\": \"stun:stun.l.google.com:19302\"},
  {\"url\":\"turn:<turn_server_ip_address>\", \"username\":\"my_username\", \"credential\":\"my_password\"}]};

pc_new = new webkitRTCPeerConnection(pc_config);

I am little confused, why are we referencing to Google\'s public STUN server. I thought RFC5766 TURN server has STUN inside it.

Is RFC5766 only TURN server? and not STUN server? Can\'t we implement our own STUN server rather using one provided by Google?

Sorry for such naive question. I am new to WebRTC.

Thanks.


回答1:


TURN it's an extension of STUN, so TURN server has also STUN features.

https://code.google.com/p/rfc5766-turn-server/ works also as a STUN, so you can try to write something like this:

var pc_config = {"iceServers": [{"url":"turn:my_username@<turn_server_ip_address>", "credential":"my_password"}]};

pc_new = new webkitRTCPeerConnection(pc_config);



回答2:


Just adding onto Igor's answer,

coturn is a fork of rfc5766-turn-server, core functionalities are same, with extra features and to which new features are added, so I would advice you to use it instead.

in author's own words:

This project evolved from rfc5766-turn-server project (https://code.google.com/p/rfc5766-turn-server/). There are many new advanced TURN specs which are going far beyond the original RFC 5766 document. This project takes the code of rfc5766-turn-server as the starter, and adds new advanced features to it.

As for Installation, it is easy to install in linux machines, not tried in other OSes.

simple way:

sudo apt-get install coturn

If you say no, I want the latest cutting edge, you can download source code from their downloads page in install it yourself, example:

sudo -i     # ignore if you already in admin mode
apt-get update && apt-get install libssl-dev libevent-dev libhiredis-dev make -y    # install the dependencies
wget -O turn.tar.gz http://turnserver.open-sys.org/downloads/v4.5.0.6/turnserver-4.5.0.6.tar.gz     # Download the source tar
tar -zxvf turn.tar.gz     # unzip
cd turnserver-*
./configure
make && make install 

for running the TURN, it is advisable to run it as a daemon, and you can use this wiki for reference for configuring it.

sample command for running TURN server:

sudo turnserver -a -o -v -n  --no-dtls --no-tls -u test:test -r "someRealm"

command description:

  • -a - Use long-term credentials mechanism
  • -o - Run server process as daemon
  • -v - 'Moderate' verbose mode.
  • -n - no configuration file
  • --no-dtls - Do not start DTLS listeners
  • --no-tls - Do not start TLS listeners
  • -u - user credentials to be used
  • -r - default realm to be used, need for TURN REST API

now you can use the TURN server in your WebRTC application as:

var peerConnectionConfig = {
  iceServers: [{
    urls: YOUR_IP:3478,
    username: 'test',
    password: 'test'
  }]
}



回答3:


Recently I was capturing my Kurento WebRTC server packets and realized that it has been using this www.stunprotocol.org domain for STUN requests. A tool named stuntman can create a simple STUN server for you.

Just follow these on a Linux host:
1.sudo apt-get update
2.sudo apt-get install stuntman-server
3.stunserver --mode full --primaryinterface 100.101.102.103 (which the 100.101.102.103 should be replaced by your IP address)
4.Open This Link to test your STUN server.
e.g. STUN or TURN URI: stun:100.101.102.103:3478

Everything goes well for me.



来源:https://stackoverflow.com/questions/22233980/implementing-our-own-stun-turn-server-for-webrtc-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!