惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
D
DataBreaches.Net
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
Docker
N
Netflix TechBlog - Medium
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
Check Point Blog
腾讯CDC
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
IT之家
IT之家
月光博客
月光博客
U
Unit 42
K
Kaspersky official blog
T
Threatpost
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
GbyAI
GbyAI
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
云风的 BLOG
云风的 BLOG
酷 壳 – CoolShell
酷 壳 – CoolShell
I
InfoQ
Engineering at Meta
Engineering at Meta
Recorded Future
Recorded Future
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security @ Cisco Blogs
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
Security Archives - TechRepublic
Security Archives - TechRepublic
Webroot Blog
Webroot Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Schneier on Security
S
Secure Thoughts
The Register - Security
The Register - Security
B
Blog RSS Feed
The Last Watchdog
The Last Watchdog
P
Palo Alto Networks Blog
爱范儿
爱范儿
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
L
LINUX DO - 热门话题
C
Cisco Blogs
Spread Privacy
Spread Privacy
F
Full Disclosure
博客园 - 聂微东
T
The Blog of Author Tim Ferriss

博客园 - 清虚真人

关于flask-sqlalchemy的用法研究 [原]跟我学silverlight系列教程[1]—wpf/silverlight体系架构和运行机制 [原]跟我学silverlight系列教程 sql2005 数据库没有完全关闭,无法重新生成日志 IIS中网站出错 javascript获取滚动条位置 - 清虚真人 - 博客园 .Net framework [转载]My97DatePicker在Frame中无法打开站点 输出datagrid的内容到excel - 清虚真人 - 博客园 sql select的时候按特定的顺序排序 vs2008 安装Silverlight tools遇到的崩溃问题。。。 .net 几种序列化类的比较 asp.net ajax实现(—):Jquery+Json WPF中BitMapEffect的性能问题 我写的PageDataSurce分页的 asp.net页面执行机制 关于服务器端控件的attributes属性的奇怪问题 关于使用javascript+asp.net实现多文件上传的若干问题 正则表达式相关教程
关于.NET中的Server push技术
清虚真人 · 2009-03-12 · via 博客园 - 清虚真人

今天突发奇想,想研究一下服务端内容有变化,如何引起客户端的改变。

一般来说方法有2种,一种就是客户端用JS异步定时轮询服务器端,这种是大部分人采用的方法,但是我在想到底可以不可以实现服务器端有改变时才会主动推送到客户端呢?按理来说这种方式对于B/S是不可能实现的,因为B/S是无连接的,这种request/response的方式无法保持状态。搜了一下,看到博客园有位朋友写了篇文章是关于Server Push的,文章点这里看,我自己把它的代码复制过来看了下效果,完整代码如下:

前台:

 1 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ServerPushDemo.aspx.cs" Inherits="WebDemo.ServerPush.ServerPushDemo" %>
 2 
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 4 
 5 <html xmlns="http://www.w3.org/1999/xhtml" >
 6 <head runat="server">
 7     <title>无标题页</title>
 8     <script type="text/javascript">
 9         function SetValue(time)
10         {
11             document.getElementById("TbTime").value=time;
12         }
13     </script>
14 </head>
15 <body>
16     <form id="form1" runat="server">
17     <div>
18         <input type="text" id="TbTime"/>
19     </div>
20     </form>
21 </body>
22 </html>
23 

后台代码:

Code

这种方式的实现原理其实就是在OnRender事件里,用循环挂起连接,因为服务器端没有response完毕,所以一直和客户端保持连接,虽然这种方式能实现服务器端向客户端的推送,但它的代价太大,因为web的优势就是无连接。这样每个客户端都要占用服务器端的一个IIS连接,如果用户超过百个,就会非常恐怖的。所以这种方式我觉得不可取,相比来说,还是用AJAX的方式定时轮询更好。

真正意义上的Server Push好像我找了一些文章在Cgi里可以实现,点这里看。但在.net里的实现我就不得而知了,知道的高人请指点下,呵呵。

我还搜到一个关于.net推技术的就是Comet框架,可以实现长连接的,具体文章请点这里。改天我会把相关Demo发出来