Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   Difficulty opening a socket (http://www.velocityreviews.com/forums/t827128-difficulty-opening-a-socket.html)

ra88it ra88it 12-20-2005 05:35 PM

Difficulty opening a socket
 
Hello,

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 =3D 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 =3D TCPSocket.new('localhost', ftp)

it works fine.

Any idea why this doesn't work (or suggestions how I could troubleshoot)?

Thanks,
r



Caleb Tennis 12-20-2005 06:40 PM

Re: Difficulty opening a socket
 
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.

Caleb



Lou Vanek 12-20-2005 07:42 PM

Re: Difficulty opening a socket
 
telnet localhost 8080

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.
>
> Caleb






Bob Showalter 12-20-2005 07:50 PM

Re: Difficulty opening a socket
 
ra88it ra88it wrote:
> Hello,
>
> 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.



mr ra88it 12-20-2005 07:59 PM

Re: Difficulty opening a socket
 
Thanks, everyone.

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.

Thanks again,
r



Bob Showalter 12-20-2005 08:16 PM

Re: Difficulty opening a socket
 
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

Here's a client to test the server:

require 'socket'
server = TCPSocket.new('localhost', 7777)
server.puts "Hello!"
puts "Server says: #{server.gets}"
server.close

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")



Bob Showalter 12-20-2005 08:18 PM

Re: Difficulty opening a socket
 
Bob Showalter wrote:
> Start the server in one window. Then go to another window and run the
> server.


Er, I mean go to another window and run the *client*



mr ra88it 12-20-2005 09:02 PM

Re: Difficulty opening a socket
 
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 =3D TCPServer.new(7777)
> while client =3D sock.accept
> puts "Connection received from #{client.peeraddr.inspect}"
> while s =3D client.gets
> client.puts s
> end
> puts "Connection from #{client.peeraddr.inspect} terminated"
> end
>
> Here's a client to test the server:
>
> require 'socket'
> server =3D TCPSocket.new('localhost', 7777)
> server.puts "Hello!"
> puts "Server says: #{server.gets}"
> server.close
>
> 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")
>
>




eching 12-20-2005 09:58 PM

Re: Difficulty opening a socket
 
I just started w/ Ruby myself (really digging it so far).

This is the exact example I was looking for; simple, yet demonstrates
so much for the beginner.

Thanks for the great example (believe it or not samples like this are
harder to find with google than one would think)



All times are GMT. The time now is 08:20 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.