require 'reel' require 'hara/base' module Hara class Server < Reel::Server include Celluloid::Logger def initialize host, port info "Server starting on #{host}:#{port}" super(host, port, &method(:on_connection)) end def on_connection(connection) while request = connection.request case request when Reel::WebSocket info "Received a WebSocket connection" handle_websocket request when Reel::Request Hara.request_handler.call connection, request else warn "Connection not support" request.close end end end Hara.request_handler do |connection, request| info "#{request.remote_ip} request #{request.url}, not support" request.close end def handle_websocket socket Hara::Application.new socket end def self.start host, port self.supervise_as :hara, host, port sleep end end end