最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How is it possible to send UDP packets to browser? - Stack Overflow

programmeradmin0浏览0评论

I know there are already similar questions in forum, but I didn't really find a direct answer for my question there.

What I'm trying to do:

I have a pub/sub middleware that uses UDP multicast to send data to other hosts and I want to be able to visualise that data with JavaScript im Browser. Best case scenario for me would be to receive the UDP packets directly in JavaScript (like just "rewriting my subscriber code in JS"), but I understand this is not possible for security reasons. So what other way is there to somehow get to these UDP packets from the browser?

I read that, under specific conditions, it's possible to municate with the browser over UDP using WebRTC, but I don't understand what these conditions are. If this would be your suggestion, it would be very nice if you could explain that. I'm kinda new to the whole real-time-data-transfer-to-browser topic.

Thank you in advance! :)

I know there are already similar questions in forum, but I didn't really find a direct answer for my question there.

What I'm trying to do:

I have a pub/sub middleware that uses UDP multicast to send data to other hosts and I want to be able to visualise that data with JavaScript im Browser. Best case scenario for me would be to receive the UDP packets directly in JavaScript (like just "rewriting my subscriber code in JS"), but I understand this is not possible for security reasons. So what other way is there to somehow get to these UDP packets from the browser?

I read that, under specific conditions, it's possible to municate with the browser over UDP using WebRTC, but I don't understand what these conditions are. If this would be your suggestion, it would be very nice if you could explain that. I'm kinda new to the whole real-time-data-transfer-to-browser topic.

Thank you in advance! :)

Share Improve this question asked Jul 7, 2021 at 12:16 alicealice 511 silver badge4 bronze badges 1
  • stackoverflow./questions/44819300/udp-socket-at-webassembly – user1390208 Commented Jul 7, 2021 at 14:14
Add a ment  | 

2 Answers 2

Reset to default 2

WebRTC provides Datachannels, this allows a browser to send/receieve datagrams. These datagrams will be carried over UDP, but also use SCTP and DTLS.

To get your packets into the browser you will need to write a UDP -> WebRTC bridge. This will not run in the browser, but the browser will connect to it. You have lots of choices when writing this bridge Python, C/C++, Go, node.js, Rust and more.

Since you are writing a bridge you could also use Websockets or even HTTP poll. But today there is no way to directly get UDP into the browser. A Raw Sockets API was proposed, but AFAIK is not going to happen.

Not for raw-UDP, but for coap(s), there are http-coap-cross-proxies, which may help.

Request out:

Browser -- HTTP -> http2coap-cross-proxy -- coap -> coap-server

Response back:

Browser <- HTTP -- http2coap-cross-proxy <- coap -- coap-server

Anyway, that keeps the request/response scheme, so I'm not sure, if that matches your requirements/expectations.

发布评论

评论列表(0)

  1. 暂无评论