javascript 我可以使用 WebRTC 打开 UDP 连接吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13811854/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 19:50:52  来源:igfitidea点击:

Can I use WebRTC to open a UDP connection?

javascriptudpwebrtc

提问by tzikis

We need send data to our users' devices using the TFTP protocol, which is a simple FTP-like protocol that works over UDP.

我们需要使用 TFTP 协议将数据发送到我们用户的设备,这是一个简单的类似 FTP 的协议,可以在 UDP 上运行。

Since we can't open a UDP socket using javascript, we have been using our server as a proxy, sending the data to our server and opening a UDP connection from the server to the device. That does have the drawback that our users need to learn about NAT and configure port forwarding.

由于我们无法使用 javascript 打开 UDP 套接字,因此我们一直使用我们的服务器作为代理,将数据发送到我们的服务器并打开从服务器到设备的 UDP 连接。这确实有一个缺点,即我们的用户需要了解 NAT 并配置端口转发。

So the question is, could we use WebRTC to open a direct UDP socket to send and receive between the browser and the devices?

那么问题来了,我们是否可以使用WebRTC打开一个直接的UDP套接字在浏览器和设备之间进行发送和接收?

http://www.webrtc.org/reference/webrtc-internals/vienetwork#TOC-SendUDPPacketsuggests that we could send some raw UDP data over the socket (that is, if it's possible to access that layer over javascript. i'm not sure about that), but I see no way to fetch a raw UDP response.

http://www.webrtc.org/reference/webrtc-internals/vienetwork#TOC-SendUDPPacket建议我们可以通过套接字发送一些原始 UDP 数据(也就是说,如果可以通过 javascript 访问该层。我是不确定),但我看不到获取原始 UDP 响应的方法。

Any help much appreciated

非常感谢任何帮助

回答by jesup

No. There are too many security issues allowing WebRTC to send to a random address/port - we have to make sure it doesn't work as a DDOS platform, so we require the target to implement ICE as an implicit permission to send data, and we also don't allow sending arbitrary data, just SRTP mediastreams and data in DataChannels (over SCTP over DTLS over UDP+ICE).

不。有太多的安全问题允许 WebRTC 发送到随机地址/端口 - 我们必须确保它不能作为 DDOS 平台工作,所以我们要求目标实现 ICE 作为发送数据的隐式许可,并且我们也不允许发送任意数据,只允许发送 SRTP 媒体流和 DataChannels 中的数据(通过 SCTP over DTLS over UDP+ICE)。

回答by nakib

No, you cannot send raw UDP data using WebRTC like that.

不,您不能像那样使用 WebRTC 发送原始 UDP 数据。

The ViENetwork lib where you can find the SendUDPPacket method is used inside Chrome to handle packet transmissions, Windows QoS support and other network settings, but you don't have direct access to it.

您可以在其中找到 SendUDPPacket 方法的 ViENetwork 库在 Chrome 中用于处理数据包传输、Windows QoS 支持和其他网络设置,但您无法直接访问它。

One of the main features of WebRTC is the Data Channelthat will bring the possibility to establish a peer-to-peer connection between two browsers, to allow raw data to be exchanged. This is still under construction in Chrome and Firefox as you can see here.

WebRTC 的主要功能之一是数据通道,它将带来在两个浏览器之间建立点对点连接的可能性,以允许交换原始数据。这仍然是正在建设中的Chrome和Firefox,你可以看到在这里

This can be what you are searching for, as you can establish a connection to send raw data and you will only have to worry in find a way to establish this connections to your other endpoint, if that's what you want.

这可能就是您要搜索的内容,因为您可以建立连接以发送原始数据,并且您只需担心找到一种方法来建立与其他端点的连接(如果这是您想要的)。