Skip to content

Instantly share code, notes, and snippets.

@tranchausky
Created August 12, 2019 02:54
Show Gist options
  • Save tranchausky/f67e9c1257ae259064cb5b80ef7e7ebc to your computer and use it in GitHub Desktop.
Save tranchausky/f67e9c1257ae259064cb5b80ef7e7ebc to your computer and use it in GitHub Desktop.
require 'socket'
server = TCPServer.new 5678
while session = server.accept
request = session.gets
puts request
session.print "HTTP/1.1 200\r\n" # 1
session.print "Content-Type: text/html\r\n" # 2
session.print "\r\n" # 3
session.print "Hello world! The time is #{Time.now}" #4
#while !request
# #puts "They said \"#{request}\"" # the server logs each response
# session.print "But why did you say \"#{request}\"?" # but it's not too bright
#end
session.print "---------------<br>"
while request !=''
request = session.gets.chomp
session.print "<br>"
session.print request
#session.print "But why did you say \"#{request}\"?" # but it's not too bright
end
session.close
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment