Tag: 客户端 服务器的

Rails ActionCable连接(服务器)与NodeJs(客户端)

我想创build一个轨道ActionCable之间的连接, NodeJs作为Client Server和NodeJs 。 这是我在connection.rb文件中的代码。 # app/channels/application_cable/connection.rb module ApplicationCable class Connection < ActionCable::Connection::Base identified_by :uuid def connect self.uuid = SecureRandom.uuid end end end 这是我的频道的代码。 # app/channels/socket_connection_channel.rb class SocketConnectionChannel < ApplicationCable::Channel def subscribed stream_from "socket_connect" end def speak ActionCable.server.broadcast("socket_connect", message: "Connected") end def unsubscribed # Any cleanup needed when channel is unsubscribed end end 这是server.js文件中的NodeJs代码 const […]