我在我的Rails 2.1应用程序上使用faye.经过测试和修复后,很多东西faye ruby client都无法正常工作.
这是我的服务器代码.
require 'faye'
server = Faye::RackAdapter.new(:mount => '/faye', :timeout => 45)
EM.run {
thin = Rack::Handler.get('thin')
thin.run(server, :Port => 9292)
server.bind(:subscribe) do |client_id, channel|
puts "[ SUBSCRIBE] #{client_id} -> #{channel}"
end
server.bind(:unsubscribe) do |client_id, channel|
puts "[UNSUBSCRIBE] #{client_id} -> #{channel}"
end
server.bind(:disconnect) do |client_id|
puts "[ DISCONNECT] #{client_id}"
end
}
Run Code Online (Sandbox Code Playgroud)
这是我的客户端JS代码.
<script type="text/javascript">
var client = new Faye.Client('http://localhost:9292/faye');
client.subscribe("/faye/new_chats", function(data) {
console.log(data);
});
</script>
Run Code Online (Sandbox Code Playgroud)
这是ruby客户端代码.
EM.run do
client = Faye::Client.new('http://localhost:9292/faye')
publication = client.publish("/faye/new_chats", { …Run Code Online (Sandbox Code Playgroud)