Sha256: 5d53e5181f149a0e1c81ef4eba7da1547bf6cda3e500e560e0e8ce66d6abd2b3

Contents?: true

Size: 918 Bytes

Versions: 2

Compression:

Stored size: 918 Bytes

Contents

require 'reel'

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
          warn "Not support normal connection"
          handle_request connection, request
        else
          warn "Not support normal connection"
          request.close
        end
      end
    end

    def handle_request connection, request
      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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hara-0.0.2 lib/hara/server.rb
hara-0.0.1 lib/hara/server.rb