Best websocket questions in October 2010

Web sockets make ajax/CORS obsolete?

5 votes

Will web sockets when used in all web browsers make ajax obsolete?

Cause if I could use web sockets to fetch data and update data in realtime, why would I need ajax? Even if I use ajax to just fetch data once when the application started I still might want to see if this data has changed after a while.

And will web sockets be possible in cross-domains or only to the same origin?

WebSockets will not make AJAX entirely obsolete and WebSockets can do cross-domain.

AJAX

AJAX mechanisms can be used with plain web servers. At its most basic level, AJAX is just a way for a web page to make an HTTP request. WebSockets is a much lower level protocol and requires a WebSockets server (either built into the webserver, standalone, or proxied from the webserver to a standalone server).

With WebSockets, the framing and payload is determined by the application. You could send HTML/XML/JSON back and forth between client and server, but you aren't forced to. AJAX is HTTP. WebSockets has a HTTP friendly handshake, but WebSockets is not HTTP. WebSockets is a bi-directional protocol that is closer to raw sockets (intentionally so) than it is to HTTP. The WebSockets payload data is UTF-8 encoded in the current version of the standard but this is likely to be changed/extended in future versions.

So there will probably always be a place for AJAX type requests even in a world where all clients support WebSockets natively. WebSockets is trying to solve situations where AJAX is not capable or marginally capable (because WebSockets its bi-directional and much lower overhead). But WebSockets does not replace everything AJAX is used for.

Cross-Domain

Yes, WebSockets supports cross-domain. The initial handshake to setup the connection communicates origin policy information. The wikipedia page shows an example of a typical handshake: http://en.wikipedia.org/wiki/WebSockets

Real time apps: Socket.io vs Pusherapp

4 votes

What are the factors you would consider when choosing between Socket.io and Pusherapp?

http://Socket.io
http://pusherapp.com

Important considerations includes: integration w existing systems like rails/django, ease of setup, ease of development

Socket.io is using Ajax long polling which requires more resources. Pusherapp on the other hand is real push. Pusherapp has various libraries, they have gem for rails, wrappers for python and GAE. You can also try other services like:

  1. Pubnub
  2. Beaconpush
  3. Hookbox
  4. Pubsubhubbub (using XMPP instead of websockets)
  5. Kwwika