Class: Rbbit::Agent

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

Overview

WebSocket Server

Instance Method Summary collapse

Constructor Details

#initialize(mb, ws_server) ⇒ Agent

Returns a new instance of Agent.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rbbit.rb', line 17

def initialize(mb, ws_server)
  @mb = mb
  #
  ws_port = (ws_server == :default ? WS_PORT : ws_server)
  run_server(ws_port)
  Kernel.sleep 1
  @con = WebSocket::Client::Simple.connect "ws://127.0.0.1:#{ws_port}"
  @con.on :message do |msg|
    #puts msg.data
  end
  @con.on :open do
    @con.send('Hello')
  end
  @con.on :close do |e|
    #p e
    #exit 1
  end
end

Instance Method Details

#send_to_ws(data) ⇒ Object



36
37
38
# File 'lib/rbbit.rb', line 36

def send_to_ws(data)
  @con.send(data)
end