-
-
Save andrewvc/887255 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
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