Ruby eventmachine httpserver 没有成功调用到 post_init

linjunhalida · 2013年11月20日 · 最后由 luikore 回复于 2013年11月20日 · 2294 次阅读

我拷贝这里面的代码:https://github.com/eventmachine/evma_httpserver

然后在 post_init 里面打了一个 puts:

require 'eventmachine'
require 'evma_httpserver'

class MyHttpServer < EM::Connection
  include EM::HttpServer

  def post_init
    super
    no_environment_strings
    puts "post init"
  end

  def process_http_request
    response = EM::DelegatedHttpResponse.new(self)
    response.status = 200
    response.content_type 'text/html'
    response.content = '<center><h1>Hi there</h1></center>'
    response.send_response
  end
end

EM.run{
  EM.start_server '0.0.0.0', 8080, MyHttpServer
}

跑起来后,终端没有任何反应,post_init 没有被调用到,不知道大家是不是也是这样?

搞错了,post_init 是在建立连接的时候创建,并不是绑定的时候创建。。

历史原因起了这么个怪名字,早叫 initialize 就好了

需要 登录 后方可回复, 如果你还没有账号请 注册新账号