# Pingecho, causing SocketError

**URL:** <https://www.ruby-forum.com/t/pingecho-causing-socketerror/192595>\
**Category:** Ruby\
**Created:** [August 2, 2010, 7:03pm UTC](https://www.ruby-forum.com/t/pingecho-causing-socketerror/192595 "2010-08-02T19:03:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![walle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/5daacb/32.png) [@walle](https://www.ruby-forum.com/u/walle)\
**Post date:** [August 2, 2010, 7:03pm UTC](https://www.ruby-forum.com/t/pingecho-causing-socketerror/192595/1 "2010-08-02T19:03:39Z")

</div>

I have a strange problem. The script posted at the end off this post is  
not working properly on one of my computers. If I run it alone, it works  
just fine, but not inside one of my scripts. The script works fine on  
all other computers that I have tested. Do anyone now what could be  
causing this.

//Walle

It raises the following exception:  
“Exception `SocketError’ at ./Handlers/ServerStatusHandler.rb:125 -  
getaddrinfo: Name or service not known”’

The script:  
def pingecho(host, timeout=5, service=“echo”)  
begin  
timeout(timeout) do  
s = TCPSocket.new(host, service)  
s.close  
end  
rescue Errno::ECONNREFUSED  
return true  
rescue Timeout::Error, StandardError  
return false  
end  
return true  
end

---

<div class="post-metadata">

**Author:** ![walle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/5daacb/32.png) [@walle](https://www.ruby-forum.com/u/walle)\
**Post date:** [August 2, 2010, 7:11pm UTC](https://www.ruby-forum.com/t/pingecho-causing-socketerror/192595/2 "2010-08-02T19:11:39Z")

</div>

For me it seems that your failing computer is unable to resolv the ip  
address of your target host. DNS misconfiguration.

Try to lookup the host with your operating systems tools like nslookup,  
dig, od dnsip.

–

Markus

---

<div class="post-metadata">

**Author:** ![walle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/5daacb/32.png) [@walle](https://www.ruby-forum.com/u/walle)\
**Post date:** [August 2, 2010, 7:20pm UTC](https://www.ruby-forum.com/t/pingecho-causing-socketerror/192595/3 "2010-08-02T19:20:44Z")

</div>

Markus S. wrote:

> For me it seems that your failing computer is unable to resolv the ip  
> address of your target host. DNS misconfiguration.
> 
> Try to lookup the host with your operating systems tools like nslookup,  
> dig, od dnsip.
> 
> –
> 
> Markus

Hey Markus,  
thanks for your response.

The thing is that the script works as intended when I run it outside,  
alone in a .rb file, but not inside one  
of my scripts. The script works as intended on all my computers but one,  
which raises that exception.  
It’s really strange.

---

<div class="post-metadata">

**Author:** ![walle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/5daacb/32.png) [@walle](https://www.ruby-forum.com/u/walle)\
**Post date:** [August 2, 2010, 7:27pm UTC](https://www.ruby-forum.com/t/pingecho-causing-socketerror/192595/4 "2010-08-02T19:27:42Z")

</div>

I’m sorry, did a small mistake. It works now.  
Thanks

//Walle
