[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

TCPSocket error

Noah

11/8/2003 10:22:00 PM

Hi all, I'm new to Ruby; I have done some Python and Perl in the past, but
just started with Ruby a few days ago.
Anyhow, when I try to open a new TCPSocket connection like so:

t = TCPSocket.new('localhost', 'http')
print t.gets
t.close

I get the following error:

socktest.rb:1:in `new': No such file or directory (Errno::ENOENT)
from socktest.rb:1

What am I doing wrong? If I make a new socket on a port where I don't have
a service listening, it will give the expected error about the target
machine refusing the connection.

ruby 1.6.8 (2002-12-24) [i586-mswin32] on WinXP-Pro

Thanks in advance,
-Noah



4 Answers

Noah

11/8/2003 10:30:00 PM

0

"Noah" <noahd@juno.nospam.com> wrote in message
news:53ec7d970ab2614e0d9f2fe91b83f37e@news.bubbanews.com...
> Hi all, I'm new to Ruby; I have done some Python and Perl in the past, but
> just started with Ruby a few days ago.
> Anyhow, when I try to open a new TCPSocket connection like so:

And yes, I do have the line
require 'socket'

So the exact code is:

require "socket"
t = TCPSocket.new('127.0.0.1', 'http')
print t.gets
t.close

with error:

6sock2.rb:2:in `new': No such file or directory (Errno::ENOENT)
from 6sock2.rb:2

Thanks


mrchameleon

11/10/2003 2:42:00 AM

0

"Noah" <noahd@juno.nospam.com> wrote in message news:
> So the exact code is:
>
> require "socket"
> t = TCPSocket.new('127.0.0.1', 'http')
> print t.gets
> t.close
>
> with error:
>
> 6sock2.rb:2:in `new': No such file or directory (Errno::ENOENT)
> from 6sock2.rb:2

From the Pickaxe book, IO.gets ...

"The stream must be opened for reading or an IOError will be raised."

How about

print t.recv(1024)

That's what I use. Hth.

Chris

Noah

11/10/2003 6:35:00 PM

0


"Chris Reay" <mrchameleon@hotmail.com> wrote in message
news:7652139e.0311091842.1d170043@posting.google.com...
> "Noah" <noahd@juno.nospam.com> wrote in message news:
> > So the exact code is:
> >
> > require "socket"
> > t = TCPSocket.new('127.0.0.1', 'http')
> > print t.gets
> > t.close
> >
> > with error:
> >
> > 6sock2.rb:2:in `new': No such file or directory (Errno::ENOENT)
> > from 6sock2.rb:2
>
> From the Pickaxe book, IO.gets ...
>
> "The stream must be opened for reading or an IOError will be raised."
>
> How about
>
> print t.recv(1024)
>
> That's what I use. Hth.
>
> Chris

Thanks, but that didn't help. The error happens on the TCPSocket.new
command.



mike

11/10/2003 8:01:00 PM

0

In article <cd6cbee83ab63b859cdb6e54544ecf1e@news.bubbanews.com>,
Noah <noahd@juno.nospam.com> wrote:

>"Chris Reay" <mrchameleon@hotmail.com> wrote in message
>news:7652139e.0311091842.1d170043@posting.google.com...
>> "Noah" <noahd@juno.nospam.com> wrote in message news:
>> > So the exact code is:
>> >
>> > require "socket"
>> > t = TCPSocket.new('127.0.0.1', 'http')
>> > print t.gets
>> > t.close
>> >
>> > with error:
>> >
>> > 6sock2.rb:2:in `new': No such file or directory (Errno::ENOENT)
>> > from 6sock2.rb:2
>>
>> From the Pickaxe book, IO.gets ...
>>
>> "The stream must be opened for reading or an IOError will be raised."
>>
>> How about
>>
>> print t.recv(1024)
>>
>> That's what I use. Hth.
>>
>> Chris
>
>Thanks, but that didn't help. The error happens on the TCPSocket.new
>command.

This is a wild guess, but might a shared library be missing, or the file
used to look up the port of the http service (/etc/services) be missing.

I would use something like strace (if it's on a unix-like system) to see
if there really is a file missing. If there is a file missing then
we can move on.

One quick thing might be to try

t = TCPSocket.new('127.0.0.1', 80)

to see if the problem is in the service name lookup.

Hope this helps,

Mike


--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co... | GPG PGP Key 1024D/059913DA
mike@exegenix.com | Fingerprint 0570 71CD 6790 7C28 3D60
http://www.exe... | 75D2 9EC4 C1C0 0599 13DA