Created
May 13, 2012 12:35
-
-
Save sawanoboly/2688238 to your computer and use it in GitHub Desktop.
TCP Simple push
This file contains hidden or 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" | |
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