TCPSocket - ECONNREFUSED


(Gabriel Paues) #1

Hi all and thanks Matz for a wonderful programming language!

I’m running ruby 1.6.7 and have a simple server (based on TCPServer) and
a client connecting to it with TCPSocket.

This works flawlessly as long as the aHostname string is ‘localhost’.
When I switch the aHostname string to a quad-dotted IPv4 address i get:

#ruby shapeclient.rb 193.10.65.97 4711 2
Tries to open 193.10.65.97…
"193.10.65.97"
shapeclient.rb:14:in open': Connection refused - "connect(2)" (Errno::ECONNREFUSED) from shapeclient.rb:14:inget_id’
from shapeclient.rb:32

The “Pragramtic Guide” tells me that:

hostName
The identifier of a network interface:

a string, which can be a host name, a dotted-quad address, or an IPV6 address in colon (and possibly dot) notation

which i think that 193.10.65.97 falls under…

Plz, help me! Is this a bug?

Sincerily,

Gabriel Paues


(ts) #2

Plz, help me! Is this a bug?

No, how do you use TCPServer::open ?

For example with this line :

pigeon% grep open b.rb
gs = TCPserver.open('localhost', 4314)
pigeon%

pigeon% ruby -rsocket -e 'TCPSocket.open("localhost", 4314)'
#<TCPSocket:0x401b8898> is accepted
#<TCPSocket:0x401b8898> is gone
pigeon%

pigeon% ruby -rsocket -e 'TCPSocket.open("138.102.114.46", 4314)'
-e:1:in `open': Connection refused - "connect(2)" (Errno::ECONNREFUSED)
        from -e:1
pigeon%

Now if I change it to

pigeon% grep open b.rb
gs = TCPserver.open(4314)
pigeon%

pigeon% ruby -rsocket -e 'TCPSocket.open("localhost", 4314)'
#<TCPSocket:0x401b8988> is accepted
#<TCPSocket:0x401b8988> is gone
pigeon%

pigeon% ruby -rsocket -e 'TCPSocket.open("138.102.114.46", 4314)'
#<TCPSocket:0x401b88e8> is accepted
#<TCPSocket:0x401b88e8> is gone
pigeon%

Guy Decoux


(Gabriel Paues) #3

Thanks!

Now it works!
I had the ‘localhost’ line in the TCPServer as you thought…

/gabriel

ts wrote:

···

Plz, help me! Is this a bug?

No, how do you use TCPServer::open ?

For example with this line :

pigeon% grep open b.rb
gs = TCPserver.open(‘localhost’, 4314)
pigeon%

pigeon% ruby -rsocket -e ‘TCPSocket.open(“localhost”, 4314)’
#TCPSocket:0x401b8898 is accepted
#TCPSocket:0x401b8898 is gone
pigeon%

pigeon% ruby -rsocket -e ‘TCPSocket.open(“138.102.114.46”, 4314)’
-e:1:in `open’: Connection refused - “connect(2)” (Errno::ECONNREFUSED)
from -e:1
pigeon%

Now if I change it to

pigeon% grep open b.rb
gs = TCPserver.open(4314)
pigeon%

pigeon% ruby -rsocket -e ‘TCPSocket.open(“localhost”, 4314)’
#TCPSocket:0x401b8988 is accepted
#TCPSocket:0x401b8988 is gone
pigeon%

pigeon% ruby -rsocket -e ‘TCPSocket.open(“138.102.114.46”, 4314)’
#TCPSocket:0x401b88e8 is accepted
#TCPSocket:0x401b88e8 is gone
pigeon%

Guy Decoux