Module: Revent::RRServer

Defined in:
lib/revent/r_r.rb

Overview

To make your class a server, just include Revent::RRServer in it.

The server has the following methods:

  • start_server

  • on_connect

  • on_unbind

  • on_message

For more control, it uses “cons” directly.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#consObject (readonly)

Returns the value of attribute cons.



81
82
83
# File 'lib/revent/r_r.rb', line 81

def cons
  @cons
end

Instance Method Details

#on_connect(con) ⇒ Object



93
94
# File 'lib/revent/r_r.rb', line 93

def on_connect(con)
end

#on_message(con, message) ⇒ Object



99
100
# File 'lib/revent/r_r.rb', line 99

def on_message(con, message)
end

#on_unbind(con) ⇒ Object



96
97
# File 'lib/revent/r_r.rb', line 96

def on_unbind(con)
end

#start_server(host, port) ⇒ Object



83
84
85
86
87
88
89
90
91
# File 'lib/revent/r_r.rb', line 83

def start_server(host, port)
  @cons = []
  EventMachine::start_server(host, port, RRCon) do |con|
    con.user = self
    # con is an instance of a class that has included RRCon
    @cons.synchronize { @cons << con }
    on_connect(con)
  end
end