0
我试图启动eventmachine httpserver示例,但我在process_http_request
方法中添加了简单的puts
。令我惊讶的是,当我从浏览器访问本地主机:8080时,我在终端中输出了两次puts
。Eventmachine调用回调两次
为什么打印两次?这是一个错误吗?也许我误解了eventmachine中的某些东西。 你可以在下面看到我的例子。
require 'eventmachine'
require 'evma_httpserver'
class MyHttpServer < EM::Connection
include EM::HttpServer
def post_init
super
no_environment_strings
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>'
puts 'my_test_string'
response.send_response
end
end
EM.run do
EM.start_server '0.0.0.0', 8080, MyHttpServer
end
哦,我应该打印出收到的数据,然后我会看到“get /favicon.ico”,但是非常感谢你:) –