Created
September 24, 2010 02:19
-
-
Save seungjin/594752 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
<html> | |
<head> | |
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js'></script> | |
<script> | |
$(document).ready(function(){ | |
ws = new WebSocket("ws://localhost:8080/"); | |
ws.onopen = function() { console.log("open"); }; | |
ws.onmessage = function(evt) { | |
ws.send("what time is it?") | |
$("#msg").append(evt.data + "<br/>"); | |
}; | |
ws.onclose = function() { console.log("socket closed"); }; | |
}); | |
</script> | |
</head> | |
<body> | |
<div id="msg"></div> | |
</body> | |
</html> |
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
require 'rubygems' | |
require 'eventmachine' | |
require 'em-websocket' | |
EventMachine.run { | |
EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080) do |ws| | |
ws.onopen { | |
puts "WebSocket connection open" | |
ws.send "You are connected" | |
ws.send Time.now | |
} | |
ws.onclose { puts "Connection closed" } | |
ws.onmessage { |msg| | |
puts Time.now | |
sleep 10 | |
ws.send Time.now | |
} | |
end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment