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?
7 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.
-
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– TimmmmApr 6, 2014 at 11:12
-
Not only that, but it's Peer 2 Peer, not great for an authoritarian server. Nov 19, 2015 at 6:32
-
14
No, it's not possible to have UDP communication within JavaScript. Sorry.
-
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: tools.ietf.org/html/draft-abarth-thewebsocketprotocol-00 Jan 11, 2011 at 22:17
-
3@IvoWetzel Why does that mean they won't? I can think of several ways to implement UDP Websockets securely.– TimmmmApr 6, 2014 at 10:41
-
41Answer is not up-to-date anymore: WebRTC webrtc.org offers (experimental) UDP in the browser and nodejs can access udp sockets on the server.– MirkoSep 13, 2015 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]: gafferongames.com/post/… [2]: github.com/RedpointGames/netcode.io-browser– DiagonSep 26, 2017 at 10:31
-
UDP/Datagram Sockets connection with node.js! The dgram module provides an implementation of UDP Datagram sockets. Feb 19, 2020 at 12:43
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.
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.
-
3If I'd want the user to install software, I could even better use Flash.– user142019Mar 31, 2011 at 14:52
-
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!
-
I think that that is very hard for a web app that is to be used by Mac and iPhone developers only. ^^'– user142019Jan 29, 2011 at 22:45
-
2Also, Silverlight doesn't support "real" UDP, only multicast UDP and that only works on LAN. Sep 27, 2011 at 20:43
-
2
You could write a WebSocket server to serve as proxy/bridge between TCP/UDP.
-
25That would defeat the entire purpose of UDP.– user142019Feb 9, 2012 at 12:53