Sha256: 34a19585e1c0ef3e7d0ae2d3156ed3aad73d7d5919a97cd3226b28f537dcb3bd

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

require 'noam_lemma'

# This is an example of a Ruby Lemma that publishes message and *also* uses the
# "Guest" model of connection. This Lemma will advertise that it's available on
# the local network, without a specified room, and will only begin speaking
# messages once a server requests a connection from the Lemma.

publisher = Noam::Lemma.new('example-guest-publisher', [], ["e3"])

# Using the `discover` method asks the Lemma to announce it's presence and
# wait for a message from a server that may want to connect to it.

publisher.discover

seq = 0
e = "e3"
loop do
  # Construct a value to send with the event.
  v = {"seq" => seq, "time" => Time.now.to_s}

  # If `speak` raises a Noam::Disconnected error, we're unable to speak the message likely because
  # the socket has closed. The connection would have to be restarted.
  begin
    publisher.speak(e, v)
  rescue Noam::Disconnected
    puts "Disconnectd"
    break
  end

  puts "Wrote: #{e} -> #{v.inspect}"

  seq += 1
  # Sleep for a while so that we don't bog down the network.
  sleep(1)
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
noam_lemma-0.2.1.3 examples/free_guest_publisher.rb