Module: Server
Instance Method Summary collapse
Instance Method Details
#run_server(addr, port, &block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/server.rb', line 5 def run_server(addr, port, &block) @_server_threads ||= {} @_server_instances ||= {} key = "#{addr}:#{port}" @_server_threads[key] = Thread.new { server = TCPServer.new(addr, port) @_server_instances[key] = server loop do client_socket = DemoSocket.new(server.accept) yield client_socket end } end |
#shutdown_server(addr, port) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/server.rb', line 21 def shutdown_server(addr, port) key = "#{addr}:#{port}" inst = @_server_instances[key] inst.shutdown if inst thread = @_server_threads[key] thread.kill if thread end |