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
原文链接:https://www.f2er.com/ajax/164293.html