Created
March 4, 2015 04:46
-
-
Save peterc/dd6aaa868320ff935a89 to your computer and use it in GitHub Desktop.
This file contains 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 './app' | |
require 'eventmachine' | |
class FingerServer < EM::Connection | |
def receive_data(data) | |
data.strip! | |
if data =~ /\A\w+\z/ | |
puts "got a request for user #{data}" | |
o = User.finger_output(data) | |
send_data(o) | |
send_data("\r\n\r\n") | |
else | |
send_data "Sorry, I can't help ya." | |
end | |
close_connection_after_writing | |
rescue | |
close_connection_after_writing | |
end | |
end | |
EventMachine.run do | |
Signal.trap("INT") { EventMachine.stop } | |
Signal.trap("TERM") { EventMachine.stop } | |
puts "Starting finger daemon on port 79" | |
EventMachine.start_server("0.0.0.0", 79, FingerServer) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment