Method: WebSocketServer#run

Defined in:
lib/web/web-socket-ruby/lib/web_socket.rb

#run(&block) ⇒ Object



474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
# File 'lib/web/web-socket-ruby/lib/web_socket.rb', line 474

def run(&block)
  @run_threads = []
  loop do
    @run_threads << Thread.start(accept()) do |s|
      begin
        ws = create_web_socket(s)
        yield(ws) if ws
      rescue => ex
        print_backtrace(ex)
      ensure
        begin
          ws.close_socket() if ws
        rescue
        end
      end
    end
  end
end