TCPSocket error

Discussion in 'Ruby' started by Noah, Nov 8, 2003.

  1. Noah

    Noah Guest

    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
    Noah, Nov 8, 2003
    #1
    1. Advertising

  2. Noah

    Chris Reay Guest

    "Noah" <> 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
    Chris Reay, Nov 10, 2003
    #2
    1. Advertising

  3. Noah

    Noah Guest

    "Chris Reay" <> wrote in message
    news:...
    > "Noah" <> 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.
    Noah, Nov 10, 2003
    #3
  4. Noah

    Mike Stok Guest

    In article <>,
    Noah <> wrote:

    >"Chris Reay" <> wrote in message
    >news:...
    >> "Noah" <> 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


    --
    | The "`Stok' disclaimers" apply.
    http://www.stok.co.uk/~mike/ | GPG PGP Key 1024D/059913DA
    | Fingerprint 0570 71CD 6790 7C28 3D60
    http://www.exegenix.com/ | 75D2 9EC4 C1C0 0599 13DA
    Mike Stok, Nov 10, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alan Davies
    Replies:
    0
    Views:
    101
    Alan Davies
    Aug 5, 2003
  2. Stephan Kämper

    TCPSocket -> Wrong error on Windows?

    Stephan Kämper, Nov 29, 2003, in forum: Ruby
    Replies:
    6
    Views:
    130
    Jon A. Lambert
    Dec 3, 2003
  3. Pat Maddox
    Replies:
    18
    Views:
    250
    Guillaume Marcais
    Apr 4, 2005
  4. Dennis Nedry
    Replies:
    5
    Views:
    148
    Dennis Nedry
    May 31, 2010
  5. Ted Pon

    TCPSocket error

    Ted Pon, Jun 2, 2010, in forum: Ruby
    Replies:
    10
    Views:
    370
    Caleb Clausen
    Jun 3, 2010
Loading...

Share This Page