Menu
  • HOME
  • TAGS

em-websocket send() send from one client to another through 2 servers

ruby-on-rails,ruby,websocket,em-websocket

I've found a way how to do it through em-websocket gem! You need just define variables outside of eventmachine block. Something like that require 'em-websocket' message_sender = nil EM.run do # message sender EM::WebSocket.run(host: '0.0.0.0', port: 19108) do |ws| ws.onopen { message_sender = ws } ws.onclose { message_sender = nil...

How do I associate an Activerecord Object with Em-Websocket connection?

ruby,activerecord,sinatra,em-websocket

I solved it by using a hash. EventMachine::WebSocket.start(host: '0.0.0.0', port: 8080) do |websock| websock.onopen do puts 'New Connection Opened' cookies = CGI::Cookie::parse( websock.request["cookie"]) person = Person.where(['token = ?', cookies["token"]]).first unless person websock.close(code = nil, body = {Error: "Invalid Token"}.to_json) unless person return end puts "#{person.name} authenticated!" # person=person.attributes.merge(websock.attributes) # Subscribe...