From: Kem Mason Date: 2008-11-14T08:50:48+09:00 Subject: Re: How to set socket option SO_RCVTIMEO hehe yeh I just realized I could use a regular Socket instead of a TCP Socket -- it doesn't appear to be the only problem though. here's my latest code (which still doesn't timeout properly) require 'socket' opt = [1, 500_000].pack("I_2") sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0) sockaddr = Socket.pack_sockaddr_in(3232, '192.168.1.10') sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_RCVTIMEO, opt) puts "sockopt = #{sock.getsockopt(Socket::SOL_SOCKET, Socket::SO_RCVTIMEO).inspect}" sock.connect(sockaddr) #this tells the server at 192.168.1.10:3232 to wait 10 seconds before responding, so we should get a timeout on our socket sock.write("10\r\n") start_time = Time.now result = sock.gets time = Time.now - start_time puts "read: #{sock.gets} after: #{time} seconds" #no timeout occured, this read returns after 10 seconds Patrick Doyle wrote: > How about something like: > > s = Socket.new(...) > s.setsockopt(Socket::SOL_SOCKET, Socket::SO_RCVTIMEO, ...) > s.connect(...) > > --wpd -- Posted via http://www.ruby-forum.com/.