Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebRTC the right one? (realtime multiplayer game)

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.)

like image 415
appsthatmatter Avatar asked Oct 12 '12 08:10

appsthatmatter


2 Answers

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.

like image 63
Sam Dutton Avatar answered Sep 28 '22 05:09

Sam Dutton


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.

like image 32
Engineer Avatar answered Sep 28 '22 07:09

Engineer