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

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

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744762382a4592247.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信