B
Bill McLean
[Note: parts of this message were removed to make it a legal post.]
All,
When using the Ruby networking library in two sample programs below I get
the connect refused exception. To validate the code, I am running both the
client and server code in separate terminal windows. The ip address given
is the address that has been assigned to the eth0 device.
The client fails to connect to the server. However if I change the ip
address to localhost or 127.0.0.1 then the connection is made.
It may not have anything to do with ruby, but with the configuration of my
linux machine.
Using ping I can explicitly ping the ip address without fail.
Any help getting this working would be appreciated.
Server.rb
require 'socket'
dts = TCPServer.new('localhost', 9900)
loop do
Thread.start(dts.accept) do |client|
print(client, "is accepted\n")
client.close
end
end
Client.rb
require 'socket'
targetIp = "192.168.0.3"
targetPort = 9900
begin
server = TCPSocket.open(targetIp, targetPort)
puts "Connected to Server" + targetIp + ":" + targetPort
server.close
rescue => ex
puts "Connection to Server Failed:
#{ex.class}: #{ex.message}"
end
Regards
Bill McLean
Technical Director
All,
When using the Ruby networking library in two sample programs below I get
the connect refused exception. To validate the code, I am running both the
client and server code in separate terminal windows. The ip address given
is the address that has been assigned to the eth0 device.
The client fails to connect to the server. However if I change the ip
address to localhost or 127.0.0.1 then the connection is made.
It may not have anything to do with ruby, but with the configuration of my
linux machine.
Using ping I can explicitly ping the ip address without fail.
Any help getting this working would be appreciated.
Server.rb
require 'socket'
dts = TCPServer.new('localhost', 9900)
loop do
Thread.start(dts.accept) do |client|
print(client, "is accepted\n")
client.close
end
end
Client.rb
require 'socket'
targetIp = "192.168.0.3"
targetPort = 9900
begin
server = TCPSocket.open(targetIp, targetPort)
puts "Connected to Server" + targetIp + ":" + targetPort
server.close
rescue => ex
puts "Connection to Server Failed:
#{ex.class}: #{ex.message}"
end
Regards
Bill McLean
Technical Director