Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to talk to UDP sockets with HTML5?

What I have : A C++ application server running, Ready to send data to client which is supposed to a HTML5 page or app.

What I want : Is there any way to communicate using udp port with HTML5 given both c++ server and HTML5 app are local to system ?

What I know :

  • Because of Security Concern, JS doesn't allow UDP port communication from browser.
  • Have read in many places, Answer is no. But answers are old.

Is the answer still 'NO' ?

Is there any work-around possible ?

Any lead is appreciated.

like image 362
mkkhedawat Avatar asked Apr 09 '15 07:04

mkkhedawat


People also ask

Can I use UDP in browser?

UDP packets are not encrypted, so any data sent over these packets could be sniffed and read by an attacker, or even modified in transmit. It would be a massive step back for web security to create a new way for browsers to send unencrypted packets.

Do UDP sockets listen?

UDP is connectionless. A server can immediately listen for messages once it has a socket.

Do UDP sockets need to bind?

As far as I remember bind is not required for a UDP socket because a bind call is made for you by the stack.


2 Answers

Yes, the answer is still 'no'. Websockets are TCP based. Note that a WebSocket is not a plain TCP connection, there is HTTP negotiation and a framing protocol in place. So you also cannot create a plain TCP connection in Javascript.

WebRTC is based on UDP, it may cover your use cases: http://www.html5rocks.com/en/tutorials/webrtc/datachannels/

like image 94
vtortola Avatar answered Sep 20 '22 18:09

vtortola


Chrome now seems to have something: https://developer.chrome.com/apps/sockets_udp

like image 24
dee Avatar answered Sep 21 '22 18:09

dee