class SPSDuplex

Public Class Methods

new(host: 'localhost', port: '55000', topic: 'chan1', sub_topic: 'node1', pub_topic: 'node2', interactive: true) click to toggle source
# File lib/sps_duplex.rb, line 11
def initialize(host: 'localhost', port: '55000', topic: 'chan1', 
               sub_topic: 'node1', pub_topic: 'node2', interactive: true)

      
  sps = SPSSub.new host: host, port: port, callback: self
  puts 'connecting ...'
  sleep 1 # give it a second to connect
  
  topic_path = [topic]
  
  if interactive then
    
    Thread.new { sps.subscribe topic: (topic_path + [sub_topic]).join('/') }

    @pub = SPSPub.new address: host, port: port
    
    topic_path << pub_topic
    @topic = topic_path.join('/')    
  else

    @pub = sps      
    @topic = (topic_path + [pub_topic]).join('/')         
    sps.subscribe topic: (topic_path + [sub_topic]).join('/')
    
  end

end

Public Instance Methods

onincoming(sender, msg) click to toggle source
# File lib/sps_duplex.rb, line 55
def onincoming(sender, msg)
  
  puts "%s: %s" % [sender, msg]
  
end
ontopic(topic, msg) click to toggle source

used by the callback routine

# File lib/sps_duplex.rb, line 47
def ontopic(topic, msg)
  
  a = topic.split('/')
  sender = a.pop
  onincoming(sender, msg)

end
send(msg) click to toggle source
# File lib/sps_duplex.rb, line 39
def send(msg)

  @pub.notice ("%s: %s" % [@topic, msg])

end