class RfidIot
module Rfidiot
Public Class Methods
new(host, port)
click to toggle source
# File lib/rfidiot.rb, line 7 def initialize host, port @host = host @port = port end
Public Instance Methods
run()
click to toggle source
# File lib/rfidiot.rb, line 11 def run EM.run do #client array @clients = [] EM::WebSocket.start(:host => @host, :port => @port) do |ws| ws.onopen do |handshake| @clients << ws puts @clients ws.send "connected" puts "Connected" end ws.onclose do ws.send "Closed." puts "closed" @clients.delete ws end ws.onmessage do |msg| puts "Received Message: #{msg}" #The data collected from the server is then sent to each of the connected clients to the server. @clients.each do |socket| socket.send msg end end end end end