Node.js websockets use UDP or TCP - javascript

How can I know which type of method uses websocket on Node js? UDP or TCP? And how can I change this? Or it depends on something else?
I'm using server on node.js and client on javascript. I don't which type of protocol uses my connection. I want to UDP, because this is game-server.
Thanks

Websockets are TCP. Here's a discussion of this issue 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.

Related

Can I establish a udp connection to a network device using javascript? [duplicate]

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?
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.
No, it's not possible to have UDP communication within JavaScript. Sorry.
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.
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!
You could write a WebSocket server to serve as proxy/bridge between TCP/UDP.

Will http3 support UDP from javascript within browser

As browsers and servers implement Http3, a lot of TCP communication will move over to UDP (QUIC).
However, it is not clear to me whether the UDP based communication primitives will be available from within the browser itself. Meaning, like one can do Ajax requests today through javascript, will browser javascript support UDP requests? Or better, large messages over UDP reliably (with necessary encryption built on top of UDP via the wrapping QUIC of course)?
This will simplify peer to peer browser communication and open up many innovative applications. Today these need to take the cumbersome STUN/TURN and WebRTC (which also uses UDP underneath) routes.
But then direct UDP has other issues, especially security concerns.
Thanks in advance.
... like one can do Ajax requests today through javascript, will browser javascript support UDP requests?
Ajax is still HTTP and not plain TCP. Ajax will continue to work and will transparently use HTTP/3 if available.
... Or better, large messages over UDP reliably (with necessary encryption built on top of UDP via the wrapping QUIC of course)?
Similar, large messages which until now used HTTP/1 or HTTP/2 over TCP will now transparently use HTTP/3 over UDP.
This will simplify peer to peer browser communication and open up many innovative applications. Today these need to take the cumbersome STUN/TURN and WebRTC (which also uses UDP underneath) routes.
No, it will not help with this. HTTP/3 will not provide plain UDP connections the same as HTTP/1 and HTTP/2 did not provide plain TCP connections.

How could I receive UDP packets from in a web browser? [duplicate]

Aside from Java Applet, is there anyway we can read from an UDP socket?
I know websockets are TCP sockets, but I need to communicate with a server via udp sockets, anything in HTML5, or anything at all?
I have looked at this post from: two years ago and this one as well again from two years ago no UDP.
I was wondering if there is any new way now that we are in 2013 to use the browser to communicate with a server via udp socket?
What you are looking for can't be done with in Javascript due to security constraints such as Distributed Denial of Service (DDOS) attacks. The closest technology available (that I know of) for client-side JS is WebRTC.
With WebRTC you can use DataChannels over SRTP and ICE as a possible solution.
See Also:
How to send a UDP Packet with Web RTC - Javascript?
Can I use WebRTC to open a UDP connection?
You can use both TCP and UDP connections with the chrome.socket API, but this is only for Packaged Apps (i.e. apps that are bundled in a container to be run as desktop apps).
The API was available for a while for Chrome extensions, when it was in experimental status (see this answer, from a user who works at Google and was co-presenter for Packaged Apps at Google I/O 2012)

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.
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/
Chrome now seems to have something: https://developer.chrome.com/apps/sockets_udp
It looks like UDP for web is still an active area of development and potential standards creation. Posting this answer to record some new info current as of May 2020.
The following whitepaper has outlined a potential path forward that satisfies the security needs for an "unreliable-unordered" protocol: https://gafferongames.com/post/why_cant_i_send_udp_packets_from_a_browser/
There are extensions to desktop Chrome and desktop Firefox that are in active development.
https://github.com/RedpointGames/netcode.io-browser
The way mobile browsers are designed prevents this kind of modification from being added at present (good security reasons again) but could be added down the road.
This is a major issue for gamers. See that link for a discussion of websockets, webrtc, quic (in chrome), and the author's netcode.io
You could alternatively create an additional python local server for bridging the data between your C++ application and webpage.
The html5 webpage connects to a local port that allows a web socket connection (use Flask/tornado).
The C++ application connects to a UDP listener on a different port. See https://wiki.python.org/moin/UdpCommunication to setup.
The python server basically forms a transparent data bridge between UDP port to websocket connection .
After reading all the links and comments, we can conclude:
NO, YOU CAN'T SEND THE UPD PACKAGE FROM THE BROWSER.
And you probably won't, because adding such a feature would be a giant leap backwards in web security.
You could possibly use a work around, design a program/script/server(I would use PHP, being a html client) to get the UDP gram from the server, if you would like I could help, I have worked on something similar.

Reading from udp port in browser

Aside from Java Applet, is there anyway we can read from an UDP socket?
I know websockets are TCP sockets, but I need to communicate with a server via udp sockets, anything in HTML5, or anything at all?
I have looked at this post from: two years ago and this one as well again from two years ago no UDP.
I was wondering if there is any new way now that we are in 2013 to use the browser to communicate with a server via udp socket?
What you are looking for can't be done with in Javascript due to security constraints such as Distributed Denial of Service (DDOS) attacks. The closest technology available (that I know of) for client-side JS is WebRTC.
With WebRTC you can use DataChannels over SRTP and ICE as a possible solution.
See Also:
How to send a UDP Packet with Web RTC - Javascript?
Can I use WebRTC to open a UDP connection?
You can use both TCP and UDP connections with the chrome.socket API, but this is only for Packaged Apps (i.e. apps that are bundled in a container to be run as desktop apps).
The API was available for a while for Chrome extensions, when it was in experimental status (see this answer, from a user who works at Google and was co-presenter for Packaged Apps at Google I/O 2012)

Categories