From: Emilio Tagua Date: 2007-04-18T23:48:58+09:00 Subject: Re: Timeout errors using Net::HTTP on Windows On 4/17/07, Toby DiPasquale wrote: > Hi all, > > I'm having a problem here running some file upload code on Windows. I've > installed Ruby 1.8.6 from the one-click installer on Windows 2000 Server > in VMware and on real hardware with Windows XP. The client, when running > on Windows, always times/errors out no matter what. Here's the error: > > c:/ruby/lib/ruby/1.8/net/http.rb:2094:in `error!': 408 "Request Timeout > " (Net::HTTPServerException) > from c:/ruby/lib/ruby/1.8/net/http.rb:2103:in `value' > from put_client.rb:25:in `upload_file' > from c:/ruby/lib/ruby/1.8/net/http.rb:543:in `start' > from put_client.rb:20:in `upload_file' > from put_client.rb:30 > > Here is the client code that is causing the problems: > > > require 'net/https' > > def upload_file url, file > uri = URI.parse url > http = Net::HTTP.new uri.host, uri.port > if uri.scheme == 'https' > http.use_ssl = true > http.verify_mode = OpenSSL::SSL::VERIFY_NONE > end > > if file.respond_to? :read > file.rewind > stream = file > length = File.size file.path > else > stream = File.open file > length = File.size file > end > > http.start do > req = Net::HTTP::Put.new uri.path > req.body_stream = stream > req.content_length = length > resp = http.request req > resp.value > end > end > > if __FILE__ == $0 > upload_file "http://localhost:8443/junk", ARGV.shift > end > > > Here is some server code I was using to test: > > > require 'webrick' > > s = WEBrick::HTTPServer.new(:Port => 8443) > > class PutServlet < WEBrick::HTTPServlet::AbstractServlet > def do_PUT(req, res) > res['Content-Type'] = "text/html" > res.body = "Uploaded #{req.body}" > end > end > > s.mount("/", PutServlet) > trap("INT"){ s.shutdown } > s.start > > > This only happens on Windows and it happens irrespective of the web > server involved. I've tried this on Mac OS X (WEBrick and nginx) and it > works fine. Running the client on Windows, though, I've tried this > against WEBrick and nginx and both exhibit the same behavior when > running the client from Windows. > > Any ideas? Thanks. You could try something like: def method begin response = Timeout::timeout(5) { Net::(whatever u want from NET Class) } ... rescue Timeout::Error puts 'Timeout!!!' .... end end Hope it helps you!