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

推荐订阅源

WordPress大学
WordPress大学
大猫的无限游戏
大猫的无限游戏
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 叶小钗
月光博客
月光博客
Last Week in AI
Last Week in AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
人人都是产品经理
人人都是产品经理
阮一峰的网络日志
阮一峰的网络日志
罗磊的独立博客
IT之家
IT之家
美团技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
S
SegmentFault 最新的问题
宝玉的分享
宝玉的分享
博客园 - Franky
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Jina AI
Jina AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Cloudflare Blog
博客园 - 司徒正美
爱范儿
爱范儿

博客园 - torome

做开发这么多年,都没有一个自己的站? 我希望四年前就有人告诉我的事情 用php_screw加密PHP代码 gSoap下Server端接口函数的数据传出 gsoap简单实例 原来CASTLE RC2 还不支持IBATIS 1.6,郁闷了很久 硬盘数据恢复原理与方法 用QQWry.Dat作数据源实现IP地址检索 缓存用户控件实例 Forms验证中的roles URL重写 使用csc命令将.cs文件编译成.dll的过程 automation服务器不能创建对象 解决 ASP.NET 中文本框上按回车时系统缺省提交按钮的问题 ASP.NET生成静态HTML页面 sql server 2000 以前的某个程序安装已在安装计算机上创建挂起的文件操作解 马斯若需求层次论 运行VS.net2003出现"找不到一个或多个组件.请重新安装" 人生的35个好习惯
js的comet各个浏览器封装lib
torome · 2011-03-10 · via 博客园 - torome

    SimpleComet是一个轻量级的comet的封装类, 能智能的识别浏览器,应用不同的comet技术,在firefox浏览器上使用ajax,在IE、opera浏览器上使用htmlfile,iframe.

<script type="text/javascript"> // This function will be called every time the server pushes a new event. function push(event) { 	// For this example, we simply show the excuse on the page. 	document.getElementById('excuse').innerHTML = event; }   // This function will be called when/if the stream closes. function disconnected() { 	// For this example we'll just show a nice message. 	document.getElementById('excuse').innerHTML = '<img src="img/arrow.png" alt="" title="" />'+ 		' Click to see MORE reasons why this souldn\'t work!'; 	document.getElementById('control').value = 'start'; }   // This function is executed when the button is clicked. function toggle() { 	// First we check if the stream is open. 	if (!comet.active) { 		// Lets start streaming! 		comet.open('excuses.php', push, disconnected); 		document.getElementById('control').value = 'stop'; 	} else { 		// Streaming is active, means the user wants to stop it. 		comet.close(); 	} } </script>

<!--?php   // First we load the SimpleComet PHP class and the list of excuses. require('inc/simplecomet.class.php'); $comet = new SimpleComet(); $excuses = file('inc/excuses.txt');   // This is an infinite loop, which makes the stream endless. while (true) { 	// We fetch an excuse at random. 	$excuse = trim($excuses[rand(0, count($excuses))]); 	// If the excuse is too long, we get another one. 	if (strlen($excuse) --> 60) { continue; } 	// Finally, we push our excuse to the client. 	$comet->push($excuse); 	// 5 seconds delay before the next excuse. 	sleep(5); }   ?>


simplecomet能监听出链接是否已经断了,是不是很智能,只要负责服务端的输出就行. 
下载: http://www.mandor.net/files/simplecomet-1.0.zip