Skip to content

Instantly share code, notes, and snippets.

@oogali
Created March 12, 2012 20:16
Show Gist options
  • Save oogali/2024416 to your computer and use it in GitHub Desktop.
Save oogali/2024416 to your computer and use it in GitHub Desktop.
time server in ruby
#!/usr/bin/env ruby
require 'rubygems'
require 'eventmachine'
require 'time'
module TimeServer
def post_init
send_data "#{Time.now.strftime('%A, %B %e, %Y %H:%M:%S')}\n"
close_connection
end
end
unless ARGV.length == 1
puts "#{$0} <port>"
exit 1
end
port = ARGV.shift.to_i
EM::run do
EM::start_server '0.0.0.0', port, TimeServer
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment