On 17 Apr 2008, at 14:20, Park Heesob wrote: >> > Try this: > > require 'timeout' > require 'socket' > > port = 1000 > server = '127.0.0.1' > > s = UDPSocket.new > s.connect(server,port) > s.write("\0") > begin > Timeout.timeout(1){s.read} > rescue Errno::ECONNREFUSED => e > puts "closed" Tells you a machine received it (hopefully the real one ;) ), and that the port was not open when the packet was received. You do not know when that was, or which packet it was. > rescue Timeout::Error > puts "open" Tells you that the machine did no actively refuse it, and *nothing else*. Many strictly configured firewalls will result in this for all UDP ports, at which point you really know nothing at all form this result, and it's highly likely they're all closed in reality, with the default rule being: protocol:udp source:any destination:any action:drop or *extremely* similar. > > ensure > s.close All this does is close the local source port, it does not close any "connection". > > end