Created
March 12, 2012 20:16
-
-
Save oogali/2024416 to your computer and use it in GitHub Desktop.
time server in ruby
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
#!/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