Skip to content

Instantly share code, notes, and snippets.

@sawanoboly
Created May 13, 2012 12:35
Show Gist options
  • Save sawanoboly/2688238 to your computer and use it in GitHub Desktop.
Save sawanoboly/2688238 to your computer and use it in GitHub Desktop.
TCP Simple push
require "socket"
gs = TCPServer.open(0, 20000)
socks = [gs]
addr = gs.addr
addr.shift
printf("server is on %s\n", addr.join(":"))
while true
Thread.start(gs.accept) do |s|
print(s, " is accepted\n")
while s.gets
%w[0 1 5 15 20 30 60 120 240 480].each do |ss|
ii = Time.now.to_i
sleep ss.to_i * 60
s.write(Time.now)
s.write("\n")
s.write((Time.now.to_i - ii) / 60)
s.write(" min\n")
end
end
print(s, " is gone")
s.close
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment