asp.net服务器推送长连接
2015-08-27 22:24
543 查看
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication18.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Asp. Server Push</title>
<script src="jquery-1.8.1.min.js"></script>
<script type="text/javascript">
function Change(str) {
window.document.getElementById("div1").innerText = str;
}
</script>
<script type="text/javascript">
$(function () {
var iframe = document.createElement("iframe");
iframe.width = 0;
iframe.height = 0;
iframe.src = 'Default.aspx';
$("#ceshi").html(iframe);
});
</script>
</head>
<body>
<div id="ceshi" style="display:none"></div>
<div style=" float:left">现在时间是:</div>
<div id="div1"></div>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication18
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected override void Render(HtmlTextWriter output)
{
string str;
while (true)
{//死循环保持长链接
str = "<script >window.parent.Change('" + DateTime.Now.ToLongTimeString() + "')</script>";
HttpContext.Current. Response.Write(str);
HttpContext.Current.Response.Flush();//输脚本调用出
}
}
}
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Asp. Server Push</title>
<script src="jquery-1.8.1.min.js"></script>
<script type="text/javascript">
function Change(str) {
window.document.getElementById("div1").innerText = str;
}
</script>
<script type="text/javascript">
$(function () {
var iframe = document.createElement("iframe");
iframe.width = 0;
iframe.height = 0;
iframe.src = 'Default.aspx';
$("#ceshi").html(iframe);
});
</script>
</head>
<body>
<div id="ceshi" style="display:none"></div>
<div style=" float:left">现在时间是:</div>
<div id="div1"></div>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication18
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected override void Render(HtmlTextWriter output)
{
string str;
while (true)
{//死循环保持长链接
str = "<script >window.parent.Change('" + DateTime.Now.ToLongTimeString() + "')</script>";
HttpContext.Current. Response.Write(str);
HttpContext.Current.Response.Flush();//输脚本调用出
}
}
}
}
相关文章推荐
- 宽带服务价值链之:ISP,ICP,ASP,IDC,CDN
- 在 ASP.NET 应用中使用 LESS
- ztree 使用asp.net mvc异步动态获取数据
- asp.net mvc htmlhelper扩展
- ASP.Net的两种开发模式
- Metasploit(四)--Msfpayload命令
- asp 数据库 模块化 - 思路是没一个页面有一个自己的数据类 这里用nPath表示
- 7 天玩转 ASP.NET MVC — 第 7 天
- 7 天玩转 ASP.NET MVC — 第 7 天
- 运行IIS出现The server has encountered an error ......的解决方法
- Metasploit(三)--Msfcli命令
- Metasploit(二)--Msf 常用***命令
- ASP 乱码问题
- Metasploit(一)--Meterpreter的命令速查表
- ASP.net,用vs做的网站后缀是.sln文件如何发布成网站?
- Aspose.Words使用教程之如何重命名合并字段
- Aspose.Words如何重命名合并字段
- aspx前台调用cs后台方法
- aspx前台调用cs后台方法
- .net学习笔记---IIS 处理模型及ASP.NET页面生命周期