Skip to content

Instantly share code, notes, and snippets.

@imanel
Created June 24, 2010 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imanel/451208 to your computer and use it in GitHub Desktop.
Save imanel/451208 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(){
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>
# 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