Skip to content

Instantly share code, notes, and snippets.

@sh7d

sh7d/geee.rb Secret

Created November 19, 2019 20:44
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 sh7d/489e7419de6716433d68c38f887762c6 to your computer and use it in GitHub Desktop.
Save sh7d/489e7419de6716433d68c38f887762c6 to your computer and use it in GitHub Desktop.
require 'socket'
READ_TOUT = 2
SERV_ADDR = '127.0.0.1'
SERV_PORT = 2000
Thread.abort_on_exception = true
c = TCPSocket.new(SERV_ADDR, SERV_PORT)
cth = Thread.new do
begin
while line = c.gets
puts line
Thread.current[:last] = Time.now.to_i
end
rescue
Thread.exit
end
end
sleep 0.5 until cth[:last]
loop do
res = Time.now.to_i - cth[:last]
if (res > READ_TEOUT)
c.close
break
end
sleep 1
end
cth.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment