Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebSockets? Is it to new to start using for Browser Based MMO based on Javascript

WebSockets? I just recently ran across websockets and have heard some good things about it but have found html5 is not really readily available at this time so would it be worth it to change over to writing a browser based MMO into websockets and getting the gamers to upgrade/download what they need or use comet and if someones browser supports websockets; run it that way? Any thoughts?

like image 812
David Avatar asked Nov 09 '10 22:11

David


People also ask

What is the difference between WebSocket and WebRTC?

WebSocket provides a client-server computer communication protocol, whereas WebRTC offers a peer-to-peer protocol and communication capabilities for browsers and mobile apps. While WebSocket works only over TCP, WebRTC is primarily used over UDP (although it can work over TCP as well).

What is socket in Javascript?

In programming, a socket is an endpoint of a communication between two programs running on a network. Sockets are used to create a connection between a client program and a server program. Sockets API is available in the Node. js net module.


1 Answers

Answer: It's not too new and you can use now on almost every browser.

WebKit has had WebSockets support for quite a while (basically anybody using Safari or Chrome has it). Starting with iOS 4.2 WebSockets have been turned on (Apple had left it de-activated in previous versions). Opera 11.0 will have it (10.7 is now 11.0). Firefox 4.0 has it included but disabled by default (enabled in about:config). Firefox 5.0 or 6.0 will likely have it on by default.

For other browsers you can use web-socket-js which is a Flash based fallback. It works well and it's easy to do automatic fallback. It is slower than native WebSockets but still has far lower latency then AJAX/COMET.

If Javascript is a valid option for the backend then you might consider using Node and the Socket.IO library for Node. Socket.IO is mainly a server-side library that supports WebSockets (it incorporates the web-socket-js falback) and various AJAX/COMET/long-poll methods. The client side of Socket.IO allows you to use the same API as on the server side (it's very similar to the normal WebSockets API) and it does detection and selects the optimal transport. The AJAX/COMET/long-poll transports are only used if the browser doesn't have native WebSockets and you choose not to use the fallback.

Included with noVNC (HTML5 VNC client) is websockify which is a WebSockets to TCP socket proxy. There are three implementations: C, python and Node. It might be a useful reference for you. noVNC transfers large amounts of data over WebSockets and it is very sensitive to latency. The Flash fallback is definitely less efficient, but it is still has very usable performance. (Disclaimer: I made noVNC)

In summary: the only place WebSockets is not supported right now is browsers without native WebSockets and without Flash (i.e. current iOS and older Android phones).

A couple of misc notes:

  • I find http://caniuse.com to be best resource for HTML5 (and related) browser support information.

  • HTML5 Cross-browser Polyfills is a very useful (and long) list of shims, fallbacks, and polyfills that add HTML5 features to browsers that don't support them.

like image 164
kanaka Avatar answered Oct 01 '22 23:10

kanaka