Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Difficulty opening a socket

Reply
Thread Tools

Difficulty opening a socket

 
 
ra88it ra88it
Guest
Posts: n/a
 
      12-20-2005
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


 
Reply With Quote
 
 
 
 
Caleb Tennis
Guest
Posts: n/a
 
      12-20-2005
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


 
Reply With Quote
 
 
 
 
Lou Vanek
Guest
Posts: n/a
 
      12-20-2005
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





 
Reply With Quote
 
Bob Showalter
Guest
Posts: n/a
 
      12-20-2005
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.


 
Reply With Quote
 
mr ra88it
Guest
Posts: n/a
 
      12-20-2005
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


 
Reply With Quote
 
Bob Showalter
Guest
Posts: n/a
 
      12-20-2005
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")


 
Reply With Quote
 
Bob Showalter
Guest
Posts: n/a
 
      12-20-2005
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*


 
Reply With Quote
 
mr ra88it
Guest
Posts: n/a
 
      12-20-2005
Thanks again, Bob et al. It works! I appreciate your help...

On 12/20/05, Bob Showalter <> 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")
>
>



 
Reply With Quote
 
eching
Guest
Posts: n/a
 
      12-20-2005
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)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Steve Holden Python 1 02-03-2009 06:20 AM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Steve Holden Python 0 02-01-2009 12:45 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 0 02-01-2009 07:37 AM
socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 1 01-27-2009 05:05 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48,'Address already in use') Jean-Paul Calderone Python 0 01-27-2009 01:41 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57