Class: Client
- Inherits:
-
Object
- Object
- Client
- Defined in:
- lib/backchannel/client.rb
Constant Summary collapse
- MULTICAST_ADDR =
"224.6.8.11"
- BIND_ADDR =
"0.0.0.0"
- PORT =
6811
Instance Method Summary collapse
- #add_message_listener(listener) ⇒ Object
-
#initialize(handle) ⇒ Client
constructor
A new instance of Client.
- #transmit(content) ⇒ Object
Constructor Details
#initialize(handle) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 |
# File 'lib/backchannel/client.rb', line 11 def initialize(handle) @handle = handle @client_id = SecureRandom.hex(5) @listeners = [] end |
Instance Method Details
#add_message_listener(listener) ⇒ Object
17 18 19 20 |
# File 'lib/backchannel/client.rb', line 17 def (listener) listen unless listening? @listeners << listener end |
#transmit(content) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/backchannel/client.rb', line 22 def transmit(content) = Message.new( "client_id" => @client_id, "handle" => @handle, "content" => content ) socket.send(.to_json, 0, MULTICAST_ADDR, PORT) end |