Ruby eventmachine httpserver 没有成功调用到 post_init

linjunhalida · November 20, 2013 · Last by luikore replied at November 20, 2013 · 2294 hits

我拷贝这里面的代码: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 就好了

You need to Sign in before reply, if you don't have an account, please Sign up first.