From: Christian Kerth Date: 2008-07-17T23:10:01+09:00 Subject: Re: "Address already in use" Error with net/http > req = Net::HTTP::Get.new(url.path) > conn = Net::HTTP.new(url.host, url.port) > > res = conn.start { > |http| > http.request(req) > } > > While the threads are running i sometimes get the Error WSAEADDRINUSE > 10048 "Address already in use" (i have a German version of Windows XP > SP2. There the exact message is: Normalerweise darf jede Socketadresse > (Protokoll, Netzwerkadresse oder Anschluss) nur jeweils einmal verwendet > werden. - connect(2)) if i perform the request like this the error is not thrown: res = conn.request(req, @data) I investigated i bit further into ruby's code and found out that if you don't call start and provide a closure, Net:HTTP.request implicitly calls start with a closure. But it modifies the req['connection'] parameter before. It sheems like this prevents the error? def request(req, body = nil, &block) # :yield: +response+ unless started? start { req['connection'] ||= 'close' return request(req, body, &block) } end . . . -- Posted via http://www.ruby-forum.com/.