Created
August 12, 2019 02:54
-
-
Save tranchausky/f67e9c1257ae259064cb5b80ef7e7ebc 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
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