I write this with some trepidation because it is probably a simple
problem (I know next to nothing about sockets), but I've tried to find
the answer on Google and no luck.
When I do this:
sock = TCPSocket.new('localhost', 8080)
I get the the "connection refused" error: Errno::ECONNREFUSED
I have tried other ports, but anyway I don't think that's the problem.
(No luck with the others, of course.)
When I do this:
sock = TCPSocket.new('localhost', ftp)
it works fine.
Any idea why this doesn't work (or suggestions how I could troubleshoot)?
Is there something listening on port 8080 on your local machine. Sockets are
a two way beast - there has to be something at the other end willing to
accept your connection.
Caleb
···
On Tuesday 20 December 2005 12:35, ra88it ra88it wrote:
When I do this:
sock = TCPSocket.new('localhost', 8080)
I get the the "connection refused" error: Errno::ECONNREFUSED
I write this with some trepidation because it is probably a simple
problem (I know next to nothing about sockets), but I've tried to find
the answer on Google and no luck.
When I do this:
sock = TCPSocket.new('localhost', 8080)
I get the the "connection refused" error: Errno::ECONNREFUSED
OK, that means no process is accepting connections on port 8080. What are you trying to do?
I have tried other ports, but anyway I don't think that's the problem.
(No luck with the others, of course.)
Why are you randomly tring ports? What are you trying to do?
When I do this:
sock = TCPSocket.new('localhost', ftp)
Do you mean 'ftp'?
it works fine.
OK, you have an FTP server running.
Any idea why this doesn't work (or suggestions how I could troubleshoot)?
"Connection refused" is pretty straighforward; there isn't a process accepting connections on the associated port. Or, you may be running tcp wrappers or something else that is causing the connection to be refused. In any event, it's not a Ruby issue.
this should indicate what's listening, if anything.
Caleb Tennis wrote:
···
On Tuesday 20 December 2005 12:35, ra88it ra88it wrote:
When I do this:
sock = TCPSocket.new('localhost', 8080)
I get the the "connection refused" error: Errno::ECONNREFUSED
Is there something listening on port 8080 on your local machine. Sockets are a two way beast - there has to be something at the other end willing to accept your connection.
Like I said, I know nothing about sockets and realize now I probably
should have asked this question elsewhere. I assumed it was not a
problem with ruby, but couldn't figure out what was wrong. I thought I
had set up a process to listen on each port that I tried, but I had
not.
Yes, Bob, I meant to type 'ftp' in quotes.
Why are you randomly tring ports? What are you trying to do?
I wasn't trying to do anything except send data over some sockets with
ruby. Just playing.
Like I said, I know nothing about sockets and realize now I probably
should have asked this question elsewhere.
It's fine. We just couldn't figure out what you're tying to do.
I wasn't trying to do anything except send data over some sockets with
ruby. Just playing.
You need to go ahead and write a simple server and a client.
Here's a simple "echo" server, that reads lines from the client and sends them back:
require 'socket'
sock = TCPServer.new(7777)
while client = sock.accept
puts "Connection received from #{client.peeraddr.inspect}"
while s = client.gets
client.puts s
end
puts "Connection from #{client.peeraddr.inspect} terminated"
end
Start the server in one window. Then go to another window and run the server.
You can also exercise your server with telnet:
telnet localhost 7777
Lines that you type will be echoed back by the server. (From telnet, you close the connection by typing the telnet "escape" character, often ^], and then typing "close")
Thanks again, Bob et al. It works! I appreciate your help...
···
On 12/20/05, Bob Showalter <bob_showalter@taylorwhite.com> wrote:
mr ra88it wrote:
> Thanks, everyone.
>
> Like I said, I know nothing about sockets and realize now I probably
> should have asked this question elsewhere.
It's fine. We just couldn't figure out what you're tying to do.
> I wasn't trying to do anything except send data over some sockets with
> ruby. Just playing.
You need to go ahead and write a simple server and a client.
Here's a simple "echo" server, that reads lines from the client and
sends them back:
require 'socket'
sock = TCPServer.new(7777)
while client = sock.accept
puts "Connection received from #{client.peeraddr.inspect}"
while s = client.gets
client.puts s
end
puts "Connection from #{client.peeraddr.inspect} terminated"
end
Start the server in one window. Then go to another window and run the
server.
You can also exercise your server with telnet:
telnet localhost 7777
Lines that you type will be echoed back by the server. (From telnet, you
close the connection by typing the telnet "escape" character, often ^],
and then typing "close")