class Hokaido::ConnectionHandler
Public Class Methods
new(connection)
click to toggle source
# File lib/hokaido/server.rb, line 10 def initialize(connection) @connection = connection async.run end
Public Instance Methods
run()
click to toggle source
# File lib/hokaido/server.rb, line 16 def run _, port, host = @connection.peeraddr puts "#{host}:#{port} connected" case @connection.gets.chomp when 'broadcast' @connection.puts ':)' while chunk = @connection.readpartial(4096) publish 'broadcast', chunk end when 'watch' @connection.puts '=)' Watcher.new(@connection).link Actor.current Kernel.sleep else @connection.puts ':(' end rescue EOFError, Errno::EIO, Errno::ECONNRESET # do nothing ensure puts "#{host}:#{port} disconnected" @connection.close end