Skip to content

Instantly share code, notes, and snippets.

@andrewvc
Forked from ian/gist:887253
Created March 25, 2011 17:46
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 andrewvc/887255 to your computer and use it in GitHub Desktop.
Save andrewvc/887255 to your computer and use it in GitHub Desktop.
class MyApp < DripDrop::Node
def action
route :my_server, :websocket_server, 'ws://127.0.0.1:9292'
my_server.on_open do |response|
EM::PeriodicTimer.new(1) do
my_client.send_message(:name => 'time_request') do |response_message|
puts "The time is: #{response_message.body['time']}"
end
end
end
end
end
MyApp.new.start!
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>untitled</title>
<script type="text/javascript" charset="utf-8" src='https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js'></script>
<script type="text/javascript" charset="utf-8">
$(function(){
var ws = new WebSocket('ws://127.0.0.1:9292');
ws.onmessage = function(message) {$('#time').text(message.data)};
ws.onerror = function(err) {console.log(err)};
ws.onclose = function(close) {console.log(close)};
});
</script>
</head>
<body>
<div id='time'></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment