Class: CanControlsGateway::OscPackage

Inherits:
Object
  • Object
show all
Defined in:
lib/osc_package.rb

Constant Summary collapse

ADDR =

broadcast address

['<broadcast>', OSC_BROADCAST_PORT]

Instance Method Summary collapse

Constructor Details

#initialize(event, station_id) ⇒ OscPackage

Returns a new instance of OscPackage.



11
12
13
14
# File 'lib/osc_package.rb', line 11

def initialize event, station_id
  @event      = event
  @station_id = station_id
end

Instance Method Details

#broadcastObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/osc_package.rb', line 16

def broadcast
  my_message = prepare_message
  my_encoded_message                = my_message.encode
  BasicSocket.do_not_reverse_lookup = true
  my_socket                         = UDPSocket.new

  my_socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true)
  my_socket.send(my_encoded_message, 0, ADDR[0], ADDR[1])
  my_socket.close

  my_encoded_message.to_s
end