Class: NyanCat::NyanServer
- Inherits:
-
GServer
- Object
- GServer
- NyanCat::NyanServer
- Defined in:
- lib/nyancat.rb
Instance Method Summary collapse
-
#initialize(port, address, options = {}) ⇒ NyanServer
constructor
A new instance of NyanServer.
- #serve(io) ⇒ Object
Constructor Details
#initialize(port, address, options = {}) ⇒ NyanServer
Returns a new instance of NyanServer.
141 142 143 144 145 146 |
# File 'lib/nyancat.rb', line 141 def initialize(port, address, = {}) @options = @options[:mute] = true @timeout = @options[:timeout] super(port, address) end |
Instance Method Details
#serve(io) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/nyancat.rb', line 148 def serve(io) n = NyanCat.new(io, @options) begin # run the animation thread t = Thread.new(n) { |nyan| nyan.run() } # block until any input is received or timeout is reached, then die Timeout::timeout(@timeout) { io.readline() } rescue Exception => e log("Client error: #{e}") ensure n.stop t.join end end |