什么是使用的WebSocket / socket.io,其中AJAX会做的缺点? [英] What is the disadvantage of using websocket/socket.io where ajax will do?

查看:277
本文介绍了什么是使用的WebSocket / socket.io,其中AJAX会做的缺点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类似的问题已经被问过,他们都得出结论,AJAX不会过时。但是,在什么样的方式就是Ajax比WebSockets的好?

Similar questions have been asked before and they all reached the conclusion that AJAX will not become obsolete. But in what ways is ajax better than websockets?

使用socket.io,很容易回落到闪存或长轮询,所以浏览器的兼容性似乎是一个不是问题的问题。

With socket.io, it's easy to fall back to flash or long polling, so browser compatibility seems to be a non-issue.

的WebSockets是双向的。其中,AJAX将成为一个异步请求,客户端的websocket将消息发送到服务器。该POST / GET参数可以连接codeD的JSON。

Websockets are bidirectional. Where ajax would make an asynchronous request, websocket client would send a message to the server. The POST/GET parameters can be encoded in JSON.

那么,什么是错用100%的WebSockets?如果每一位来访者保持一个持久的WebSocket连接到服务器时,会认为比惠顾会议上做了一些Ajax请求更多的浪费?

So what is wrong with using 100% websockets? If every visitor maintains a persistent websocket connection to the server, would that be more wasteful than making a few ajax requests throughout the visit session?

推荐答案

我认为这将是更多的浪费。对于每一个连接的客户端,你需要某种形式的对象/功能/ code /任何服务器上的配对与一个客户端。一个套接字句柄或文件描述符,或者不管你的服务器所处理的连接。

I think it would be more wasteful. For every connected client you need some sort of object/function/code/whatever on the server paired up with that one client. A socket handler, or a file descriptor, or however your server is setup to handle the connections.

使用AJAX,你并不需要一个1:1的映射服务器端资源为客户端。你的#的客户可以扩展比你的服务器端资源较少的依赖性。即使node.js中有它的局限性,有多少个连接,它可以处理,并保持开放。

With AJAX you don't need a 1:1 mapping of server side resource to client. Your # of clients can scale less dependently than your server-side resources. Even node.js has its limitations to how many connections it can handle and keep open.

另外要考虑的是,某些AJAX响应可以被缓存了。当你扩展你可以添加一个HTTP缓存,以帮助降低负载频繁AJAX请求。

The other thing to consider is that certain AJAX responses can be cached too. As you scale up you can add an HTTP cache to help reduce the load from frequent AJAX requests.

这篇关于什么是使用的WebSocket / socket.io,其中AJAX会做的缺点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆