Skip to content

Instantly share code, notes, and snippets.

@cvonkleist
Created November 17, 2010 22:04
Show Gist options
  • Save cvonkleist/704188 to your computer and use it in GitHub Desktop.
Save cvonkleist/704188 to your computer and use it in GitHub Desktop.
forking retarded web server
require 'socket'
listener = TCPServer.new(8888)
loop do
puts 'waiting for connection...'
sock = listener.accept
fork do
puts 'i am child'
filename = sock.gets.split[1]
begin
sock.puts 'HTTP/1.0 200 OK', File.read(filename)
rescue
sock.puts 'HTTP/1.0 404 OH SNAP', '', 'WHERE IZ FILEZ?'
end
puts 'child done'
exit 0
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment