js的comet各个浏览器封装lib
SimpleComet是一个轻量级的comet的封装类, 能智能的识别浏览器,应用不同的comet技术,在firefox浏览器上使用ajax,在IE、opera浏览器上使用htmlfile,iframe.
// 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 = ''+ ' 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(); } }
// 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
转载于:https://www.cnblogs.com/torome/archive/2011/03/10/1979944.html
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
'