加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

why websocket over ajax

发布时间:2020-12-16 00:19:42 所属栏目:百科 来源:网络整理
导读: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
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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读