How to talk to UDP sockets with HTML5?

前端 未结 6 1013
执笔经年
执笔经年 2020-12-05 02:07

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 :

相关标签:
6条回答
  • 2020-12-05 02:16

    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/

    0 讨论(0)
  • 2020-12-05 02:17

    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

    0 讨论(0)
  • 2020-12-05 02:23

    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 .

    0 讨论(0)
  • 2020-12-05 02:25

    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.

    0 讨论(0)
  • 2020-12-05 02:27

    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.

    0 讨论(0)
  • 2020-12-05 02:33

    Chrome now seems to have something: https://developer.chrome.com/apps/sockets_udp

    0 讨论(0)
提交回复
热议问题