Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何向每个连接发送消息_Ruby On Rails_Ruby_Websocket_Ruby On Rails 5_Actioncable - Fatal编程技术网

Ruby on rails 如何向每个连接发送消息

Ruby on rails 如何向每个连接发送消息,ruby-on-rails,ruby,websocket,ruby-on-rails-5,actioncable,Ruby On Rails,Ruby,Websocket,Ruby On Rails 5,Actioncable,我知道,在ActionCable中,ping的工作方式如下: def beat transmit type: ActionCable::INTERNAL[:message_types][:ping], message: Time.now.to_i end 但是,当我尝试使用connect进行传输时,只有一个connecton使用传输获取我的消息,为什么 def connect self.uuid = SecureRandom.uuid transmit({'title': 'pla

我知道,在ActionCable中,ping的工作方式如下:

def beat
  transmit type: ActionCable::INTERNAL[:message_types][:ping], message: Time.now.to_i
end
但是,当我尝试使用connect进行传输时,只有一个connecton使用
传输
获取我的消息,为什么

def connect
  self.uuid = SecureRandom.uuid
  transmit({'title': 'players_online', 'message': 'A new user has been subscribed'})
end

其实很容易:

ActionCable.server.connections.each do |connection|
  connection.transmit({'title': 'players_online', 'message': ActionCable.server.connections.size})
end

也许只有一个订户?检查谁订阅了。@Sylar 3订阅者使用更多代码更新帖子,以便我可以复制。您的客户端代码在哪里?你到处都在订阅这条消息吗?@maxpleaner我正在使用SocketRocket从iOS订阅