Created
June 24, 2010 09:11
-
-
Save imanel/451208 to your computer and use it in GitHub Desktop.
This file contains 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(){ | |
function debug(str){ $("#debug").append("<p>" + str); }; | |
ws = new WebSocket("ws://localhost:8080/"); | |
ws.onmessage = function(evt) { $("#msg").append("<p>"+evt.data+"</p>"); }; | |
ws.onclose = function() { debug("socket closed"); }; | |
ws.onopen = function() { | |
debug("connected..."); | |
ws.send("hellö"); | |
}; | |
}); | |
</script> | |
</head> | |
<body> | |
<div id="debug"></div> | |
<div id="msg"></div> | |
</body> | |
</html> |
This file contains 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' | |
require 'json' | |
EM.run { | |
EM::WebSocket.start(:host => "0.0.0.0", :port => 8080) do |ws| | |
ws.onmessage { |msg| | |
puts "Received message: #{msg}" | |
ws.send msg.to_json | |
} | |
end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment