why websocket over ajax

前端之家收集整理的这篇文章主要介绍了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

原文链接:https://www.f2er.com/ajax/164293.html

猜你在找的Ajax相关文章