带 UDP 的 JavaScript WebSocket? ?

我正在编写一个 JavaScript 应用程序,它必须接收来自其他用户的大量数据。这些数据是否丢失并不重要。有没有什么方法可以用 UDP 代替 TCP 来使用 JavaScriptWebSocket?

80401 次浏览

No, it's not possible to have UDP communication within JavaScript. Sorry.

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.

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!

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.

You could write a WebSocket server to serve as proxy/bridge between TCP/UDP.

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.

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.