Class: SPSPub
- Inherits:
-
Object
- Object
- SPSPub
- Defined in:
- lib/sps-pub.rb
Class Method Summary collapse
- .notice(s, hostx = 'sps', host: hostx, address: host, port: '59000', retries: 3) ⇒ Object
- .pub(s, address: 'sps', host: address, port: '59000') ⇒ Object
- .publish(s, address: 'sps', host: address, port: '59000') ⇒ Object
Instance Method Summary collapse
-
#initialize(host: 'sps', address: host, port: '59000') ⇒ SPSPub
constructor
A new instance of SPSPub.
- #notice(s) ⇒ Object
- #publish ⇒ Object
Constructor Details
#initialize(host: 'sps', address: host, port: '59000') ⇒ SPSPub
Returns a new instance of SPSPub.
10 11 12 13 14 15 16 |
# File 'lib/sps-pub.rb', line 10 def initialize(host: 'sps', address: host, port: '59000') @client = WebSocket::Client::Simple.connect "ws://%s:%s/" % [address, port] sleep 0.02 end |
Class Method Details
.notice(s, hostx = 'sps', host: hostx, address: host, port: '59000', retries: 3) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/sps-pub.rb', line 24 def self.notice(s, hostx='sps', host: hostx, address: host, port: '59000', retries: 3) ws = WebSocket::Client::Simple.connect "ws://%s:%s/" % [address, port] ws.on :open do retry_attempts = 0 begin ws.send s sleep 0.02 # give the above message time to be sent rescue Errno::ETIMEDOUT => e if retries and retry_attempts < retries then retries += 1 puts 'SPSPub timeout retrying ...' retry else puts 'SPSPub timeout while trying to contact the host' end end end :message_sent end |
.pub(s, address: 'sps', host: address, port: '59000') ⇒ Object
58 59 60 |
# File 'lib/sps-pub.rb', line 58 def self.pub(s, address: 'sps', host: address, port: '59000') self.notice(s, address: 'sps', port: '59000') end |
.publish(s, address: 'sps', host: address, port: '59000') ⇒ Object
62 63 64 |
# File 'lib/sps-pub.rb', line 62 def self.publish(s, address: 'sps', host: address, port: '59000') self.notice(s, address: 'sps', port: '59000') end |
Instance Method Details
#notice(s) ⇒ Object
18 19 20 |
# File 'lib/sps-pub.rb', line 18 def notice(s) @client.send s end |
#publish ⇒ Object
22 23 24 |
# File 'lib/sps-pub.rb', line 22 def notice(s) @client.send s end |