将特定端口用于webRTC [英] Use specific ports for webRTC

查看:444
本文介绍了将特定端口用于webRTC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用webRTC创建对等音频连接时,如果用户在路由器后面,我们使用的STUN服务器将返回公共IP.现在在ICE对象中,我可以看到rport始终在50000以上.

When creating a peer to peer audio connection using webRTC, the STUN server we use will return the public IP if a user is behind a router. Now in the ICE objects, I can see that the rport is always something between 50000 and up.

是否有一种使用特定端口的方法,以便用户不必打开所有这些端口?

Is there a way to use a specific port so that the user does not have to open all those ports?

推荐答案

是否有一种使用特定端口的方法,以便用户不必打开所有这些端口?

Is there a way to use a specific port so that the user does not have to open all those ports?

我认为您有误会.存在STUN和ICE(包括其WebRTC派生词)的全部要点是为了避免任何人都必须在其NAT上打开端口.相反,STUN和ICE动态地打开端口.

I think you have a misunderstanding. The whole point of STUN and ICE (including its WebRTC derivative) exists to avoid anyone having to open a port on their NAT. Instead, STUN and ICE dynamically open the port.

这是它的工作原理(在非常简短的描述中).

Here's how it works (in a really brief description).

  1. 客户端在随机端口(例如50001)上打开套接字

  1. Client opens a socket on a random port (e.g. 50001)

使用该套接字与STUN服务器联系,以发现此套接字的外部IP:端口映射. (例如192.168.1.2:50001映射到1.2.3.4:50001).端口不一定必须在内部地址和外部地址之间进行匹配,但是它们通常会匹配,因此在此示例中,我将继续使用.

Contacts STUN server using that socket to discover the external IP:port mapping for this socket. (e.g. 192.168.1.2:50001 maps to 1.2.3.4:50001). Ports don't necessarily have to match between internal and external addresses, but they usually do, so I'll keep with that for this example.

通过外部机制(SIP,XMPP,Jingle,带字符串的杯子),两个节点的候选地址列表被交换.这包括收集的所有已知内部和外部地址(例如192.168.1.2:50001和1.2.3.4:50001).

Through an external mechanism (SIP, XMPP, Jingle, cups with strings), the candidate address list of both nodes are exchanged. This includes all known internal and external addresses collected (e.g. 192.168.1.2:50001 and 1.2.3.4:50001).

使用在步骤1中打开的同一套接字,双方直接在彼此之间发送(STUN)消息(UDP数据包).第一对消息可能会被路由器/防火墙阻止.但是由于一侧发起了到远程地址的出站数据包,因此允许该地址的后续数据包返回.这称为打孔步骤".因此,端口是动态开放的,无需路由器进行任何特定的配置.

Using the same socket opened in step 1, both sides send (STUN) messages (UDP packets) directly between each other. The first pair of messages may be blocked by the router/firewall. But because one side initiated an outbound packet to the remote address, subsequent packets from that address are allowed back in. This is called the "hole punching step". Hence, the port is dynamically open without the router needing any specific configuration.

希望这会有所帮助.

这篇关于将特定端口用于webRTC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆