Skip to content

Instantly share code, notes, and snippets.

@seungjin
Created September 24, 2010 02:19
Show Gist options
  • Save seungjin/594752 to your computer and use it in GitHub Desktop.
Save seungjin/594752 to your computer and use it in GitHub Desktop.
<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>
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