How to send a UDP Packet with Web RTC – Javascript?

You can’t send a UDP packet directly with WebRTC. That would violate the basic security constraints required by the browser.

You can send SRTP to an ICE-enabled host. That is probably not what you are looking for.

If a browser permitted sending arbitrary UDP packets, then malicious applications could send packets to any host.

This might not sound so bad, after all, hosts on the Internet need to be able to deal with that right? The problem is that some browsers are in protected environments where access to the network is restricted. Within those networks, some hosts are far less protected than a host on the public Internet might be. This would be OK, since access to the network is controlled.

If it were possible for a browser to send arbitrary packets, a user on a browser in that environment could be convinced to send specifically crafted packets to one of these poorly protected hosts. Likely, that would result in the network operator banning the browser, which is something browser-makers want very much to avoid.

WebRTC only sends certain types of UDP packet under specific conditions. If the host that you are interested in talking to understands ICE and is able to consume RTP with SRTP or SCTP over DTLS (unlikely methinks). Then perhaps you could force the browser to send something.

Leave a Comment