Simple socket server not working?

Discussion in 'Ruby' started by Stephen Ware, Oct 10, 2007.

  1. Stephen Ware

    Stephen Ware Guest

    (Just to avoid easy questions...)

    I am using 'telnet <myserver> 5056'.

    I have tried using a different port number.

    The ports are not blocked on my server.
    --
    Posted via http://www.ruby-forum.com/.
     
    Stephen Ware, Oct 10, 2007
    #1
    1. Advertising

  2. Stephen Ware

    Stephen Ware Guest

    Any idea why this code...

    require 'socket'
    server = TCPServer.new('127.0.0.1', 5056)
    socket = server.accept
    socket.puts('it works')
    socket.flush

    doesn't work on my Unix server? If I run it in the background, I can
    connect from the same machine using telnet and it works fine... but I
    cannot connect from any remote machines.

    What am I missing?
    --
    Posted via http://www.ruby-forum.com/.
     
    Stephen Ware, Oct 10, 2007
    #2
    1. Advertising

  3. Stephen Ware

    Stephen Ware Guest

    Hmm... seem to have fixed my own problem. I just removed the
    'localhost' parameter from the TCPServer and it works fine.
    --
    Posted via http://www.ruby-forum.com/.
     
    Stephen Ware, Oct 10, 2007
    #3
  4. T24gQmVoYWxmIE9mIFN0ZXBoZW4gV2FyZToNCiMgc2VydmVyID0gVENQU2VydmVyLm5ldygnMTI3
    LjAuMC4xJywgNTA1NikNCiAgICAgICAgICAgICAgICAgICAgICAgICBeXl5eXl5eXl5eDQogICAg
    ICAgICAgICAgICAgICAgICAgICAgbG9vcGJhY2sgYWRkcmVzcw0KDQojIEkgY2FuIGNvbm5lY3Qg
    ZnJvbSB0aGUgc2FtZSBtYWNoaW5lIHVzaW5nIHRlbG5ldCAuLg0KIyBjYW5ub3QgY29ubmVjdCBm
    cm9tIGFueSByZW1vdGUgbWFjaGluZXMuDQoNCmxvb3BiYWNrIGFkZHJlc3MgaXMgbm90IGFjY2Vz
    c2libGUgcmVtb3RlbHkNCg0KdHJ5IHVzaW5nIGFkZHJlc3Mgb2YgeW91ciBuZXR3b3JrIGNhcmQu
    LiAoZWcgaSB0cmllZCBtaW5lIGF0IDEwLjIuMTAuMTIzIGFuZCBpdCB3b3Jrcy4uKQ0KDQpraW5k
    IHJlZ2FyZHMgLWJvdHANCg==
     
    Peña, Botp, Oct 10, 2007
    #4
  5. Stephen Ware

    Mat Schaffer Guest

    On Oct 9, 10:54 pm, Stephen Ware <> wrote:
    > Any idea why this code...
    >
    > require 'socket'
    > server = TCPServer.new('127.0.0.1', 5056)
    > socket = server.accept
    > socket.puts('it works')
    > socket.flush
    >
    > doesn't work on my Unix server? If I run it in the background, I can
    > connect from the same machine using telnet and it works fine... but I
    > cannot connect from any remote machines.
    >
    > What am I missing?


    A firewall perhaps? Does it work locally but not from a remote
    machine? The code worked fine for me totally locally, so I think the
    problem is network-related.
    -Mat
     
    Mat Schaffer, Oct 10, 2007
    #5
  6. Stephen Ware

    Ari Brown Guest

    On Oct 9, 2007, at 11:49 PM, Stephen Ware wrote:

    > Hmm... seem to have fixed my own problem. I just removed the
    > 'localhost' parameter from the TCPServer and it works fine.


    As a quick summary of the problem, 127.0.0.1 is ONLY accessible from
    your local machine. :)

    If you try it with your network IP address, make sure you don't have
    any firewalls blocking it.

    HTH
    Ari
    --------------------------------------------|
    If you're not living on the edge,
    then you're just wasting space.
     
    Ari Brown, Oct 10, 2007
    #6
  7. Stephen Ware

    Jon Lambert Guest

    Jon Lambert, Oct 10, 2007
    #7
  8. Stephen Ware wrote:
    > Any idea why this code...
    >
    > require 'socket'
    > server = TCPServer.new('127.0.0.1', 5056)
    > socket = server.accept
    > socket.puts('it works')
    > socket.flush
    >
    > doesn't work on my Unix server? If I run it in the background, I can
    > connect from the same machine using telnet and it works fine... but I
    > cannot connect from any remote machines.
    >
    > What am I missing?


    Using the machine's network address. Something like
    server = TCPServer.new( '111.222.111.2' , 5056)
    should do the trick.

    127.0.0.1 is the loopback address, which (AFAIK) means that socket
    won't get anywhere near the outside network, it will all
    be handled internally. Hence you cannot connect to it from outside your
    unix server.

    Martin.
     
    Martin Portman, Oct 10, 2007
    #8
    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. SpreadTooThin
    Replies:
    4
    Views:
    359
    Fredrik Lundh
    Oct 6, 2006
  2. Laszlo Nagy
    Replies:
    1
    Views:
    4,928
    Mark Wooding
    Jan 27, 2009
  3. Jean-Paul Calderone
    Replies:
    0
    Views:
    993
    Jean-Paul Calderone
    Jan 27, 2009
  4. Laszlo Nagy
    Replies:
    0
    Views:
    566
    Laszlo Nagy
    Feb 1, 2009
  5. Steve Holden
    Replies:
    0
    Views:
    685
    Steve Holden
    Feb 1, 2009
Loading...

Share This Page