1

在 Rails 应用程序上运行 faye 服务器时出现此错误。我已经安装了 eventmachine gem,并且还需要在 faye 的初始化文件中使用 eventmachine。

/Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/gems/eventmachine-1.0.0/lib/eventmachine.rb:664:in `connect_server': eventmachine not initialized: evma_connect_to_server (RuntimeError)
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/gems/eventmachine-1.0.0/lib/eventmachine.rb:664:in `bind_connect'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/gems/eventmachine-1.0.0/lib/eventmachine.rb:640:in `connect'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/gems/faye-websocket-0.4.6/lib/faye/websocket/client.rb:19:in `initialize'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/gems/faye-0.8.6/lib/faye/transport/web_socket.rb:51:in `new'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/gems/faye-0.8.6/lib/faye/transport/web_socket.rb:51:in `connect'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/gems/faye-0.8.6/lib/faye/transport/web_socket.rb:26:in `usable?'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/gems/faye-0.8.6/lib/faye/transport/web_socket.rb:11:in `usable?'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/gems/faye-0.8.6/lib/faye/transport/transport.rb:82:in `block in get'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/gems/faye-0.8.6/lib/faye.rb:103:in `call'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/gems/faye-0.8.6/lib/faye.rb:103:in `block in async_each'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/gems/faye-0.8.6/lib/faye.rb:110:in `call'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/gems/faye-0.8.6/lib/faye.rb:110:in `block in async_each'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/gems/faye-0.8.6/lib/faye.rb:117:in `call'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/gems/faye-0.8.6/lib/faye.rb:117:in `block in async_each'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/gems/faye-0.8.6/lib/faye.rb:119:in `call'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/gems/faye-0.8.6/lib/faye.rb:119:in `async_each'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/gems/faye-0.8.6/lib/faye/transport/transport.rb:97:in `get'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/gems/faye-0.8.6/lib/faye/protocol/client.rb:311:in `select_transport'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/gems/faye-0.8.6/lib/faye/protocol/client.rb:35:in `initialize'
from /Users/vivekvivek/website/faye.ru:38:in `new'
from /Users/vivekvivek/website/faye.ru:38:in `block in <main>'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
from /Users/vivekvivek/website/faye.ru:1:in `new'
from /Users/vivekvivek/website/faye.ru:1:in `<main>'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:40:in `eval'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:40:in `parse_file'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/server.rb:200:in `app'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/server.rb:301:in `wrapped_app'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/server.rb:252:in `start'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/server.rb:137:in `start'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/bin/rackup:4:in `<top (required)>'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/bin/rackup:19:in `load'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/bin/rackup:19:in `<main>'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in `eval'
from /Users/vivekvivek/.rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in `<main>'

我突然收到这个错误,感谢您的帮助。

4

1 回答 1

1
require 'faye'
require 'eventmachine'

EM.run do
  client = Faye::Client.new('http://localhost:9292/faye')
  publication = client.publish("/faye/new_chats", {
      "user" => "ruby-logger",
      "message" => "Got your message!"
  })
  publication.callback do
    puts "[PUBLISH SUCCEEDED]"
  end
  publication.errback do |error|
    puts "[PUBLISH FAILED] #{error.inspect}"
  end
end
于 2012-11-27T06:15:47.503 回答