Class: Net::PingUDP
Overview
With a UDP ping, send a simple text string and check the return string. If they match, assume success.
Constant Summary
Constants inherited from Ping
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Attributes inherited from Ping
#exception, #host, #port, #timeout, #warning
Instance Method Summary collapse
-
#ping ⇒ Object
(also: #ping?)
Sends a simple text string and checks the return string.
Methods inherited from Ping
Constructor Details
This class inherits a constructor from Net::Ping
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
96 97 98 |
# File 'lib/net/ping.rb', line 96 def data @data end |
Instance Method Details
#ping ⇒ Object Also known as: ping?
Sends a simple text string and checks the return string. If they match, the ping was successful.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/net/ping.rb', line 100 def ping super success = false udp = UDPSocket.open a = [] begin Timeout.timeout(@timeout){ udp.connect(@host, @port) udp.send(@data, 0) a = udp.recvfrom(64) } rescue Exception => err @exception = err else if a[0] == @data success = true end ensure udp.close if udp end success end |