public
Description: my random codes
Homepage: http://anilwadghule.com/blog
Clone URL: git://github.com/anildigital/anil-code.git
Search Repo:
anil-code / simple_server.rb
100755 13 lines (12 sloc) 0.356 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
# Simple Webserver in Ruby
# author: Anil Wadghule
#!ruby
require 'socket'
port = ARGV[0] || '3002'.to_i
server = TCPServer.new('localhost', port)
while (sess = server.accept)
  puts "Request: #{sess.gets}"
  sess.print "HTTP/1.1 200/OK\r\nContent-type: text/html\r\n\r\n"
  sess.print "<html><body><h1>#{Time.now}</h1></body></html>\r\n"
  sess.close
end