我怀疑这是因为浏览器正在期待HTTP头响应& c。奇怪的是,如果你在“确保”睡一秒钟之前,你可以每次都发生“重置”错误。
如何解决这个问题取决于你在做什么。如果这不是一个HTTP服务器,那么请不要使用浏览器来测试它。相反,使用telnet或写一个小程序。如果它是一个HTTP服务器,那么看一下webrick,这是内置于Ruby MRI> = 1.8的。具体方法如下:我
#!/usr/bin/ruby1.8
require 'webrick'
# This class handles time requests
class TimeServer < WEBrick::HTTPServlet::AbstractServlet
def do_GET(request, response)
response.status = 200
response['Content-Type'] = 'text/plain'
response.body = Time.now.to_s
end
end
# Create the server. There are many other options, if you need them.
server = WEBrick::HTTPServer.new(:Port=>8080)
# Whenever a request comes in for the root page, use TimeServer to handle it
server.mount('/', TimeServer)
# Finally, start the server. Does not normally return.
server.start
谢谢。我已经在玩它,它不会产生这个错误。尽管如此,我仍然很好奇,如果最初的例子可以修复。在C#中,有可能在超时套接字上调用`Close`,它可以解决.NET世界中同样的问题。 – detunized 2011-01-06 21:11:07