nodejs:阿贾克斯VS Socket.IO,利弊 [英] nodejs: Ajax vs Socket.IO, pros and cons

查看:111
本文介绍了nodejs:阿贾克斯VS Socket.IO,利弊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想过摆脱所有客户端Ajax调用(jQuery的),而是使用永久套接字连接(Socket.IO)的。

I thought about getting rid of all client-side Ajax calls (jQuery) and instead use a permanent socket connection (Socket.IO).

所以我会用事件监听器/发射器的客户端和服务器端。

Therefore I would use event listeners/emitters client-side and server-side.

例。 click事件是由用户在浏览器中触发,客户端射推动通过socket连接到服务器的事件。服务器端监听反作用于输入事件,并推动完成事件回客户端。客户端的监听器衰落DIV元素反作用于传入事件。

Ex. a click event is triggered by user in the browser, client-side emitter pushes the event through socket connection to server. Server-side listener reacts on incoming event, and pushes "done" event back to client. Client's listener reacts on incoming event by fading in DIV element.

这是否有道理呢? 赞成&安培;缺点是什么?

Does that make sense at all? Pros & cons?

推荐答案

发送单向消息,并调用回调对他们可能会变得非常混乱。

Sending one way messages and invoking callbacks to them can get very messy.

$得到('/ API,送出数据,returnFunction); 比清洁剂 socket.emit(sendApi',送出数据); socket.on(recieveApi',returnFunction);

这就是为什么dnode何建在socket.io使事情变得可管理的顶部nowjs。还是事件驱动,但没有放弃回调。

Which is why dnode and nowjs where built on top of socket.io to make things manageable. Still event driven but without giving up callbacks.

这篇关于nodejs:阿贾克斯VS Socket.IO,利弊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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