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

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)

Related

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.

Node.js websockets use UDP or TCP

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.

connect to C# server from javascript

Is it possible to create a javascript program that connect to a simple C# server using a simple socket and not a WebSocket.
can you help me with a sample.
There is no standard way to make a TCP connection from Javascript code running in a web browser. (See the answer by #Johannes Hahn)
To communicate between your client and server, consider Microsoft's SignalR library. It is designed to allow a Javascript program, running in the browser, to communicate with a C# server. SignalR will use websockets; however, it will continue to work if websockets are not available by falling back to other transports. You can also specify transports, if you need to prevent it from attempting to use websockets.
SignalR connection starts as HTTP, and is then promoted to a WebSocket connection if it is available. WebSocket is the ideal transport for SignalR, since it makes the most efficient use of server memory, has the lowest latency, and has the most underlying features (such as full duplex communication between client and server), but it also has the most stringent requirements: WebSocket requires the server to be using Windows Server 2012 or Windows 8, and .NET Framework 4.5. If these requirements are not met, SignalR will attempt to use other transports to make its connections.
Also, be aware that if your Javascript is not running in a web browser, you can make regular network connections. For example, a Javascript application running on Node.js.
It seems that at least Firefox is supposed to know about socket, see https://developer.mozilla.org/en-US/docs/Web/API/TCP_Socket_API. But (taken from the same source) TCP or UDP sockets are not part of any standard and therefore likely either unsupported or completely different in other browsers.
In principle no. For security reasons browsers only allow a limited set of protocols. Chrome has a socket API, but that is not standard - https://developer.chrome.com/apps/sockets_tcp. There are solutions which use a WebSocket connection to a server which then establishes a TCP socket connection, e.g. https://github.com/kanaka/websockify, http://artemyankov.com/tcp-client-for-browsers/, so if you can't add WebSocket directly to the server you may want to check these out.

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