TCPSocket error

N

Noah

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
 
C

Chris Reay

Noah said:
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
 
N

Noah

Chris Reay said:
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.
 
M

Mike Stok

Noah said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top