Created
May 29, 2014 21:44
-
-
Save Najaf/a4ea22d5c073c6f2ae52 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 'socket' | |
def log( source, message) | |
time = Time.now.strftime("%Y-%m-%d %H:%M:%S") | |
puts "[%s] %s => %s" % [time, source, message] | |
end | |
server = TCPServer.new ARGV.first.to_i | |
loop do | |
client = server.accept | |
info = client.remote_address | |
source = "%s:%s" % [info.ip_address, info.ip_port] | |
log source, "Connection established" | |
request_line = client.readline | |
log source, "Method = %s | URI = %s | Version = %s" % request_line.split | |
client.close | |
log source, "Connection terminated" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment