Reputation: 6417
Imagine I want to create a realtime multiplayer game, with HTML5 (client) and node.js (server).
I need to transport data very fast from the server to the clients and vice versa.
In a native application I would use UDP
for the most data (player position, ...), because it's way faster than TCP
and it's uncritical when it is lost.
In HTML5
I can (only) use WebSockets
. WebSockets is on top of TCP and thus not fast enough for a good performance.
I heard about WebRTC
, but I don't know whether this could be the solution for this problem.
Has anybody experience with it?
(I know, that WebRTC is still unsupported for the most browser, but that doesn't matter to me.)
Upvotes: 9
Views: 4967
Reputation: 8847
RTCDataChannel provides session-based / reliable as well as connectionless / unreliable transport, analogous to TCP and UDP in a native client, respectively. More information here. As of 2013, this is a viable technology, albeit only in later Chrome and Firefox builds.
According to html5rocks.com, it is also now possible to use binary types for transfer. So you should have all the capabilities you would have with an efficient, native UDP client. However, I am as yet uncertain whether binary transfer has made it's way from the webrtc repository, where it has been fixed, all the way into Chrome, or whether it's still only available in Chrome Canary at this stage.
Upvotes: 1
Reputation: 15269
In terms of WebRTC, sounds like what you need is DataChannel: see draft protocol and HTML5 Rocks article (disclaimer: I wrote it!)
DataChannel is a work in progress, not yet implemented by any browser.
As for other WebRTC components, MediaStream (getUserMedia) is supported by Chrome, Firefox Nightlies and Opera; RTCPeerConnection is in Chrome stable, behind a flag (flagless in forthcoming versions), and promised for Firefox 18 in Q1 2013.
EDIT: RTCDataChannel has now been implemented on Firefox and Chrome.
Chrome 'single page' demo: simpl.info/dc, Firefox demo.
Upvotes: 2