我拷贝这里面的代码: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 没有被调用到,不知道大家是不是也是这样?