【问题标题】:How to send a UDP package in browser using HTML5 or WEBRTC?如何使用 HTML5 或 WEBRTC 在浏览器中发送 UDP 包?
【发布时间】:2016-03-23 09:18:37
【问题描述】:

我想在浏览器中向我的 UDP 服务器发送一个 UDP 包。听说HTML5或者WEBRTC可以做点什么,不知道怎么做。

有人可以帮我吗?

【问题讨论】:

标签: html browser udp webrtc


【解决方案1】:

您可以编写一个 chrome 扩展程序(应用程序),让您可以访问 https://developer.chrome.com/apps/sockets_udp(manifest.json 中的"sockets": {...})。

或者,就 WebRTC 而言:

var pc = new webkitRTCPeerConnection(
    { "iceServers": [{ "url": "stun:localhost:1234" }] }
);

pc.createOffer(function (sessionDescription) {
    pc.setLocalDescription(sessionDescription);

}, function(error) {
    alert(error);
}, { 'mandatory': { 'OfferToReceiveAudio': true, 'OfferToReceiveVideo': true } });

然后您就可以通过以下方式在 localhost:1234 上获取 UDP 数据包:

$port = 1234

t = Thread.start do
  server = UDPSocket.open
  server.bind(nil, $port)
  a = server.recvfrom(12364)
  puts server.send "ping", 0, a[1][2], a[1][1]
end
t.join

【讨论】:

  • 我知道数据格式,如何发送我的数据,例如,我的数据是[0x80,0x01,0x11]。
  • 我会考虑构建一个 chrome 扩展然后:developer.chrome.com/apps/sockets_udp#method-send。
  • 显然 UDP 套接字在扩展中是不可能的了。这在某一时刻是可能的,但出于安全考虑,他们禁用了它——仅限于 Chrome 应用程序,这些应用程序现在也正在结束/逐步淘汰。 ://
  • 我能够使用这个webkitRTCPeerConnection API 获得一些包,但它们似乎是加密的。我如何实际解析/阅读它?另外,我如何发送我的数据,例如一些文本?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-31
  • 2014-11-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多