Bill Kelly wrote:
From: "Matthew Margolis" <
[email protected]>
I can not get a working TCPSocket under windows with ruby 1.8.2. It
just hangs. Is there currently a solution for this problem?
Could you post your code? I've used TCPSocket (and UDPSocket)
heavily under Win32 ruby since, I think version 1.6.4... Currently
running ruby 1.8.2 (2004-12-25) [i386-mswin32].
sure
-----------------
require 'Timeout'
require 'socket'
time =5
begin
Timeout.timeout(time) do
s = TCPSocket.new("google.com", "echo")
puts "fish"
s.close
end
rescue Timeout::Error
puts "Timed out"
end
Note, the above code also hangs under Linux, too.
I think it's just that google.com doesn't answer
connection requests on port 7 (echo).
Here's similar code (in irb on Windows) using http
instead of echo:
=> true
=> nil
=> "HTTP/1.0 200 OK\r\n"
=> "Cache-Control: private\r\n"
=> "Content-Type: text/html\r\n"
=> "Set-Cookie: PREF=ID=5eb25ab2dffff310:TM=1109793965:LM=1109793965:
S=MmppHbq23LjrmaeH; expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/;
domain=.google.com\r\n"
=> "Server: GWS/2.1\r\n"
=> "Date: Wed, 02 Mar 2005 20:06:05 GMT\r\n"
=> "Connection: Close\r\n"
=> "\r\n"
=> "<html><head><meta http-equiv=\"content-type\" content=\"text/html;
=> nil
HTH,
Regards,
Bill