Hi, ----- Original Message ----- From: "Kr Alfabeta" <kristis / micro.lt> Newsgroups: comp.lang.ruby To: "ruby-talk ML" <ruby-talk / ruby-lang.org> Sent: Thursday, April 17, 2008 8:58 PM Subject: Re: checking connection to server:port > Thank you for all replays. Now everything is more clear. In php manual: > > UDP sockets will sometimes appear to have opened without an error, even > if the remote host is unreachable. The error will only become apparent > when you read or write data to/from the socket. The reason for this is > because UDP is a "connectionless" protocol, which means that the > operating system does not try to establish a link for the socket until > it actually needs to send or receive data. > > So in conclusion there is no way to check that UDP port is working or > not? Maybe there is a common query which you can send by UDP and then > receive any response? 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" rescue Timeout::Error puts "open" ensure s.close end Regards, Park Heesob