why websocket over ajax

To handle chat-related messaging, you could poll the server with Ajax. But to make
this application as responsive as possible, you’ll avoid using traditional Ajax as a means
to send messages. Ajax uses HTTP as a transport mechanism, and HTTP wasn’t
designed for real-time communication. When a message is sent using HTTP, a new
TCP/IP connection must be used. Opening and closing connections takes time, and
the size of the data transfer is larger because HTTP headers are sent on every request.
Instead of employing a solution reliant on HTTP, this application will prefer Web-
Socket (http://en.wikipedia.org/wiki/WebSocket), which was designed as a bidirec-
tional lightweight communications protocol to support real-time communication.
Since only HTML5-compliant browsers, for the most part, support WebSocket, the
application will leverage the popular Socket.IO library (http://socket.io/), which
provides a number of fallbacks, including the use of Flash, should using WebSocket
not be possible. Socket.IO handles fallback functionality transparently, requiring no
additional code or configuration. 


From: Node.js in action

你可能感兴趣的:(why websocket over ajax)