Class: Vizcore::Sync::OscReceiver
- Inherits:
-
Object
- Object
- Vizcore::Sync::OscReceiver
- Defined in:
- lib/vizcore/sync/osc_receiver.rb
Overview
Receives OSC UDP messages on a background thread.
Constant Summary collapse
- DEFAULT_HOST =
"127.0.0.1"- MAX_PACKET_SIZE =
65_536
Instance Method Summary collapse
-
#initialize(port:, host: DEFAULT_HOST, handler:, error_reporter: nil) ⇒ OscReceiver
constructor
A new instance of OscReceiver.
- #start ⇒ Vizcore::Sync::OscReceiver
- #stop ⇒ nil
Constructor Details
#initialize(port:, host: DEFAULT_HOST, handler:, error_reporter: nil) ⇒ OscReceiver
Returns a new instance of OscReceiver.
17 18 19 20 21 22 23 24 25 |
# File 'lib/vizcore/sync/osc_receiver.rb', line 17 def initialize(port:, host: DEFAULT_HOST, handler:, error_reporter: nil) @host = host.to_s @port = Integer(port) @handler = handler @error_reporter = error_reporter @socket = nil @thread = nil @running = false end |
Instance Method Details
#start ⇒ Vizcore::Sync::OscReceiver
28 29 30 31 32 33 34 35 36 |
# File 'lib/vizcore/sync/osc_receiver.rb', line 28 def start return self if @thread&.alive? @socket = UDPSocket.new @socket.bind(@host, @port) @running = true @thread = Thread.new { receive_loop } self end |
#stop ⇒ nil
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/vizcore/sync/osc_receiver.rb', line 39 def stop @running = false @socket&.close @thread&.join(1) nil rescue StandardError nil ensure @socket = nil @thread = nil end |