can we open an UDP conection in javascript

506 Views Asked by At

I think all is in the title, I want to use socket in js with UDP. I tried with WebSocket but : Uncaught SyntaxError: Failed to construct 'WebSocket': The URL's scheme must be either 'ws' or 'wss'. 'udp' is not allowed. Is it possible with socket.io ? if yes how to use socket.io without node.js ? Maybe ther is a socket.io.min.js.
Thanks you for your help.

1

There are 1 best solutions below

0
On BEST ANSWER

No, it is not possible. Websocket connections are an 'upgrade' based on HTTP, an HTTP is based on TCP/IP. So, inherently, you cannot open a UDP connection, since for even getting a websocket connection started, you will already have a TCP/IP connection going.

However, if you really do need UDP, you could implement something on your server side that actually does the UDP connection and act as a proxy, where your server opens the UDP connection with more low level libraries. You are of course less limited on the server than you are in a browser.