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」,但是非常感謝你:) –