alice
alice

Reputation: 51

How is it possible to send UDP packets to browser?

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 communicate 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! :)

Upvotes: 3

Views: 8603

Answers (2)

Achim Kraus
Achim Kraus

Reputation: 824

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.

Upvotes: 1

Sean DuBois
Sean DuBois

Reputation: 4232

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.

Upvotes: 2

Related Questions