【问题标题】:Faye, Rails and Net:HTTP end of file reachedFaye、Rails 和 Net:到达 HTTP 文件结尾
【发布时间】:2012-05-04 18:13:21
【问题描述】:

我正在尝试完成以下任务:网站上的帖子一经批准,就会通知该网站上的人。

为了解决这个问题,我正在使用 Faye,并在我的方法批准的频道上发布。我的应用程序只有一个通道,非常简单的场景。无论如何,由于某种原因它无法正常工作。

我正在使用 Rails 2.3.5Faye 0.8.5eventmachine 1.0.0.beta4(与 Faye 一起安装的那个) 、机架 1.0.1瘦 1.3.1。我没有使用 Apache。

到目前为止我所拥有的是:

faye.ru:(我运行它:rackup faye.ru -s thin -E production)

require 'faye'

faye_server = Faye::RackAdapter.new(:mount => '/faye', :timeout => 45)
run faye_server

application.js

var $j = jQuery.noConflict();

$j(function() {
  var faye = new Faye.Client('http://0.0.0.0:9292/faye');
  faye.subscribe("/messages/new", function(data) {
    alert(data.text);
  });
});

application.html.erb

<%= javascript_include_tag 'http://0.0.0.0:9292/faye.js' %>

posts_controller.rb

def approve
  @post.update_attribute(:approved, true)
  message = {:post => @post}
  uri = URI.parse("http://0.0.0.0:9292/faye")
  Net::HTTP.post_form(uri, :message => message.to_json)
  redirect_to(pending_posts_path)
end

堆栈跟踪是:

EOFError (end of file reached):
  /usr/lib/ruby/1.8/net/protocol.rb:135:in `sysread'
  /usr/lib/ruby/1.8/net/protocol.rb:135:in `rbuf_fill'
  /usr/lib/ruby/1.8/timeout.rb:62:in `timeout'
  /usr/lib/ruby/1.8/timeout.rb:93:in `timeout'
  /usr/lib/ruby/1.8/net/protocol.rb:134:in `rbuf_fill'
  /usr/lib/ruby/1.8/net/protocol.rb:116:in `readuntil'
  /usr/lib/ruby/1.8/net/protocol.rb:126:in `readline'
  /usr/lib/ruby/1.8/net/http.rb:2024:in `read_status_line'
  /usr/lib/ruby/1.8/net/http.rb:2013:in `read_new'
  /usr/lib/ruby/1.8/net/http.rb:1050:in `request'
  /usr/lib/ruby/1.8/net/http.rb:405:in `post_form'
  /usr/lib/ruby/1.8/net/http.rb:543:in `start'
  /usr/lib/ruby/1.8/net/http.rb:404:in `post_form'
  app/controllers/posts_controller.rb:38:in `approve'

并且在瘦服务器上也出现错误

>> Thin web server (v1.3.1 codename Triple Espresso)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:9292, CTRL+C to stop
!! Unexpected error while processing request: undefined method `call' for nil:NilClass

据我了解,每次尝试连接服务器时都会出现此错误,关键是“http://0.0.0.0:9292/faye.js”不可用,即如果我尝试访问此 URL,我收到“!! Unexpected error while processing request: undefined method `call' for nil:NilClass”,这也是 Net:HTTP 无法访问它的原因.我想知道为什么。

【问题讨论】:

    标签: ruby-on-rails faye


    【解决方案1】:

    不要输入&lt;%= javascript_include_tag 'http://0.0.0.0:9292/faye.js' %&gt;

    它不完全是本地主机,只是这样做:

    &lt;%= javascript_include_tag 'http://127.0.0.1:9292/faye.js' %&gt;

    【讨论】:

    • 感谢您的帮助,在某些时候我最终放弃了与 Faye 的尝试,但知道您指出了这一点,我将重新设置它并进行测试。我将带着结果返回。谢谢!
    • 不起作用,我已经尝试过,仍然是同样的问题。无论如何,谢谢。
    【解决方案2】:

    终于找到问题了,我的错,我忘了用服务器开始监听,在faye.ru:

    faye_server.listen(9292)
    

    【讨论】:

      猜你喜欢
      • 2011-07-11
      • 2013-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多