Created
January 19, 2016 10:30
-
-
Save aj07/09c9cfd0977f4dda70e6 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('localhost', 8080) | |
loop do | |
socket = server.accept | |
request = socket.gets | |
STDERR.puts request | |
response = "Hello World!\n" | |
p begin | |
x=Time.now;sleep 80; "#{Time.now-x} seconds have passed" | |
rescue Exception | |
puts "#{$!} (#{$!.class})" | |
$stdout.flush | |
raise $! | |
end | |
socket.print "HTTP/1.1 200 OK\r\n" + | |
"Content-Type: text/plain\r\n" + | |
"Content-Length: #{response.bytesize}\r\n" + | |
"Connection: close\r\n" | |
socket.print "\r\n" | |
socket.print response | |
socket.close | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Exposes a GET API as "api/serverStatus"
This API returns all the running requests on the server with their time left for
completion. E.g {"2":"15","8":"10"} where 2 and 8 are the connIds and 15 and 10
is the time remaining for the requests to complete (in seconds).