Class: OSC::Server
- Inherits:
-
Object
- Object
- OSC::Server
- Defined in:
- lib/ruby-osc/server.rb
Defined Under Namespace
Classes: Connection
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#port ⇒ Object
Returns the value of attribute port.
Instance Method Summary collapse
- #add_pattern(pattern, &block) ⇒ Object
- #delete_pattern(pattern) ⇒ Object
-
#initialize(port, address = "127.0.0.1") ⇒ Server
constructor
A new instance of Server.
- #receive(data) ⇒ Object
- #run ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(port, address = "127.0.0.1") ⇒ Server
Returns a new instance of Server.
5 6 7 8 9 10 |
# File 'lib/ruby-osc/server.rb', line 5 def initialize(port, address = "127.0.0.1") @port, @address = port, address @queue, @patterns = [], [] @mutex = Mutex.new run end |
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
3 4 5 |
# File 'lib/ruby-osc/server.rb', line 3 def address @address end |
#port ⇒ Object
Returns the value of attribute port.
3 4 5 |
# File 'lib/ruby-osc/server.rb', line 3 def port @port end |
Instance Method Details
#add_pattern(pattern, &block) ⇒ Object
23 24 25 26 |
# File 'lib/ruby-osc/server.rb', line 23 def add_pattern(pattern, &block) raise ArgumentError, "A block must be given" unless block @patterns << [pattern, block] end |
#delete_pattern(pattern) ⇒ Object
28 29 30 |
# File 'lib/ruby-osc/server.rb', line 28 def delete_pattern(pattern) @patterns.delete pattern end |
#receive(data) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ruby-osc/server.rb', line 32 def receive(data) case decoded = OSC.decode(data) when Bundle decoded..nil? ? decoded.each{ |m| dispatch m } : @mutex.synchronize{@queue.push(decoded)} when Message dispatch decoded end rescue => e warn "Bad data received: #{ e }" end |
#run ⇒ Object
12 13 14 15 |
# File 'lib/ruby-osc/server.rb', line 12 def run @connection = EventMachine.open_datagram_socket @address, @port, Connection, self check_queue end |
#stop ⇒ Object
17 18 19 20 21 |
# File 'lib/ruby-osc/server.rb', line 17 def stop return unless @connection @connection.close_connection @timer.cancel end |