Skip to content

Instantly share code, notes, and snippets.

@aj07
Created January 19, 2016 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aj07/09c9cfd0977f4dda70e6 to your computer and use it in GitHub Desktop.
Save aj07/09c9cfd0977f4dda70e6 to your computer and use it in GitHub Desktop.
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
@aj07
Copy link
Author

aj07 commented Jan 19, 2016

  • 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment