Created
June 12, 2009 23:48
-
-
Save sorah/129015 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createHttpRequest(){//XMLHttpRequestのブラウザ間の違いを補助する関数 | |
if(window.ActiveXObject){ | |
try { | |
return new ActiveXObject("Msxml2.XMLHTTP") | |
} catch (e) { | |
try { | |
return new ActiveXObject("Microsoft.XMLHTTP") | |
} catch (e2) { | |
return null | |
} | |
} | |
} else if(window.XMLHttpRequest){ | |
return new XMLHttpRequest() | |
} else { | |
return null | |
} | |
} | |
function requestFile(){//読み込み | |
var hobj = createHttpRequest(); | |
hobj.open('GET','comet.rb',true);//GETメソッドでcomet.rbを非同期で読み込みます | |
hobj.onreadystatechange = function() {//readyStateが変更されたときのイベント | |
if (hobj.readyState==4) {//readyStateが4ならば(読み込み完了) | |
mesobj = document.getElementById("message"); | |
mesobj.innerHTML += hobj.responseText+"<br/>";//出力して | |
//mesobj.innerHTML = hobj.responseText + mesobj.innerHTML; | |
setTimeout(requestFile,1000);//一秒後に再読み込み(即時で読み込みを開始すると、0秒時点で6回ぐらい呼ばれるため) | |
} | |
} | |
hobj.send('');//読み込みを開始 | |
} | |
requestFile(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
print "Content-Type: text/html\r\n\r\n"#text/htmlで出力します宣言。改行は\r\nを2つ。これは必須。 | |
loop do#無限ループ | |
mytime = Time.now#現在時刻を取得 | |
if mytime.sec == 0#現在秒が0ならば | |
print mytime.to_s+"\r\n"#出力して | |
break#ループを抜ける | |
end | |
sleep 1#負荷防止 | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Cometテスト</title> | |
<script type="text/javascript" src="comet.js"></script> | |
</head> | |
<body> | |
<div id="message">時報が表示されます。</br></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment