.NET(c#)服务器推送代码

| |
[2008/05/13 17:44 | 分类: DotNet技术 | by gdgzboy ]
建立一份新的aspx页面,在aspx.cs里的page_load里加上如下代码...然后保存,访问一下...就可以看到服务器推送模式的效果了...

        protected void Page_Load(object sender, EventArgs e)
        {
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.ContentType = "multipart/x-mixed-replace;boundary=--TempString--";
            HttpContext.Current.Response.StatusCode = 200;
            HttpContext.Current.Response.Write("");
            HttpContext.Current.Response.Write("--TempString--\r\n");
            HttpContext.Current.Response.Flush();
            while (HttpContext.Current.Response.IsClientConnected)
            {
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.Write("date : " + DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss") + "\r\n");
                HttpContext.Current.Response.Write("--TempString--\r\n");
                HttpContext.Current.Response.Flush();
                Thread.Sleep(1000);
            }
        }


            


作者:gdgzboy@牛C网
地址:http://www.niuc.net/post/4209/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!



评论(3) | 引用(0) | 阅读(978)
gattaca Says:
2008/09/19 13:45
試過了確實可行!
我現在把源碼放在xxx.ashx.cs中,
實現新聞跑馬燈效果.

感謝!!
CAI Says:
2008/08/01 15:47
占资源好厉害啊
你只服务器?还是客户端
gdgzboy 回复于 2008/08/01 21:31
wangchengh Says:
2008/07/25 14:39
测试过不行,ie会一直装入但是没有内容显示出来,cpu使用率达100%
我测试过可行啊
gdgzboy 回复于 2008/07/25 21:34
分页: 1/1 第一页 1 最后页
发表评论
昵称 [注册]
密码 游客无需密码
网址
电邮
打开HTML 打开UBB 打开表情 隐藏 记住我