Server Push: WebSocket与它的前辈们

 

Piaoger正在用Node.js与socket.io配合实现一个Realtime WebSevice,但总归是半路出家,需要了解其来龙去脉,这样的话可以更清晰地明白为什么会有这玩意以及怎样利用它的特点。

 

# Polling (轮询)

Poll Server for updates, wait at client.

利用JavaScript的setInterval,每隔一段时间向Server发送一个Request,如此往复。

优点:

实现容易,Server端无需特别处理

缺点:

需要重新创建Connect,效率低下,浪费带宽

# Streaming Comet (永不消逝的电波)

In a Web application using streaming Comet, the browser opens a single persistent connection to the server for all Comet events and handles them incrementally on the browser side.

两种实现方式:Hidden IFrame, AJAX.

 

## Streaming Comet (Ajax)

在这种方式中,Client和Server建立长久连接,Server端会有一个thread.sleep, 在Sever端做Polling的工作。

 

## Streaming Comet (Hidden iFrame)

有人也叫做Forever Frame.JavaScript以unchunked block的形式发送给隐藏的IFrame,这些JavaScript会在Browser执行。

优点: 实现方便 / 跨浏览器

缺点: 不能像XMLHttpRequest那样可以跟踪Request Progress。

 

# Long Polling

同之前Streaming Comet不同,Long Polling的做法是发送一个长时间等待的Request,当Server端有数据Response的时候,立即断掉,结果发送一个新的Request。

 

 

# WebSocket

HTML5 WebSocket

 在Googld Chrome中,我们可以Debug WebSocketFrames。

# References

[Browser 與 Server 持續同步的作法介紹 (Polling, Comet, Long Polling, WebSocket)] (http://hi.baidu.com/skicean/item/4a479dd6dba6f9ba33db9095)

[Comet Programming: Using Ajax to Simulate Server Push] (http://www.webreference.com/programming/javascript/rg28/index.html)

[Comet Programming: the Hidden IFrame] (http://Techniquewww.webreference.com/programming/javascript/rg30/index.html)

[Push_technology) (http://en.wikipedia.org/wiki/Push_technology)

转载于:https://www.cnblogs.com/piaoger/archive/2012/08/19/2646698.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值