Created
June 21, 2016 02:57
-
-
Save toretore/24dcef14e76f66aa21d5264aaf13dd20 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' | |
def log(s) | |
puts "#{Time.now.strftime('%H:%M:%S')}: #{s}" | |
end | |
server = TCPServer.new('', 1337) | |
loop do | |
socket = server.accept | |
log "New connection, new socket" | |
s = socket.recv(1024) | |
log "#{s.bytesize}b: #{s.split("\r\n")[0]}" | |
if socket.eof? | |
log "Socket closed by browser" | |
else | |
log "Sending response" | |
socket.puts "HTTP/1.1 200 OK" | |
socket.puts 'Content-Length: 0' | |
socket.puts | |
socket.close | |
end | |
puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment