I'm writing a JavaScript Application that has to receive a huge amount of data from other users. It is not important if some of this data gets lost. Is there some way of using JavaScript WebSockets with UDP instead of TCP?
-
2It can be done over webRTC. https://geckosio.github.io/ game server uses this technique. – Fost Aug 10 '20 at 14:36
8 Answers
It sounds like what you're waiting for is WebRTC which is working it's way through the standards process. WebSockets, as other people have pointed out, run over TCP as a result of initiating with an HTTP Upgrade.

- 2,064
- 1
- 22
- 29
-
6WebRTC looks almost great, but as far as I can tell you have to use RTCDataChannel for data communication, and that uses SCTP which doesn't support unreliable deliveries (necessary for games). Edit: Cancel that, it does support an unreliable mode. [Good article here](http://www.html5rocks.com/en/tutorials/webrtc/datachannels/) – Timmmm Apr 06 '14 at 11:12
-
Not only that, but it's Peer 2 Peer, not great for an authoritarian server. – NiCk Newman Nov 19 '15 at 06:32
-
14
No, it's not possible to have UDP communication within JavaScript. Sorry.

- 11,291
- 4
- 29
- 45

- 176,835
- 32
- 241
- 292
-
2@TimeMachine They won't WebSockets built on top of TCP, the initial handshake is also made so that it is recognized as an HTTP upgrade request by web servers. You can read more about the protocol in the latest draft: http://tools.ietf.org/html/draft-abarth-thewebsocketprotocol-00 – Ivo Wetzel Jan 11 '11 at 22:17
-
3@IvoWetzel Why does that mean they won't? I can think of several ways to implement UDP Websockets securely. – Timmmm Apr 06 '14 at 10:41
-
41Answer is not up-to-date anymore: WebRTC http://www.webrtc.org/ offers (experimental) UDP in the browser and nodejs can access udp sockets on the server. – Mirko Sep 13 '15 at 11:53
-
Here's a [discussion of this issue][1] in relation to gaming. There he covers websockets, webrtc (a possible choice for UDP, but complicated), quic (only in google chrome), and his [netcode.io][2]. [1]: https://gafferongames.com/post/why_cant_i_send_udp_packets_from_a_browser/ [2]: https://github.com/RedpointGames/netcode.io-browser – Diagon Sep 26 '17 at 10:31
-
[UDP/Datagram Sockets](https://nodejs.org/api/dgram.html) connection with node.js! The dgram module provides an implementation of UDP Datagram sockets. – Derk Jan Speelman Feb 19 '20 at 12:43
-
@ Derk Jan Speelman - I'm not sure if he wants a UDP implementation that works with browser JavaScript. I don't see any indication that it works with browsers. I think WebRTC is still the best solution. – Benargee Aug 25 '20 at 01:33
Sounds like the question is meant for client-side UDP, but since I ended up here...
You can do UDP in JavaScript on the server using the node.js dgram
package.

- 1,334
- 15
- 14
The WebSockets protocol is over TCP only as currently defined.
You could do UDP with Flash if you are willing to use a RTMFP (Real Time Messaging Flow Protocol) server.
If this question is still pending: I found a project called JNEXT and there is an example using UDP. The project itself seems to be paused but at least in Firefox it works (it doesn't work with Chrome and Opera). May be it is worth to look for it.

- 19
- 1
As of HTTP/3 Release, there is a new Protocol for the browser called WebTransport,WebTransport_API and it supports the UDP protocol, Similar to WebSockets but with support for multiple streams, till then the only way to use UDP in the browser was to use WebRTC streams

- 977
- 10
- 15
I think you can leverage Silverliht 4 technology. You can create a Silverlight 4 application to communicate with server and then enbamdded it to html page. Then your JavaScript can build TCP connections via Silverlight 4 application!

- 23
- 1
-
I think that that is very hard for a web app that is to be used by Mac and iPhone developers only. ^^' – Jan 29 '11 at 22:45
-
2Also, Silverlight doesn't support "real" UDP, only multicast UDP and that only works on LAN. – Martin Ørding-Thomsen Sep 27 '11 at 20:43
-
2