[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Simple socket server not working?

Stephen Ware

10/10/2007 2:54:00 AM

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-....

4 Answers

Peña, Botp

10/10/2007 4:46:00 AM

0

On Behalf Of Stephen Ware:
# server = TCPServer.new('127.0.0.1', 5056)
^^^^^^^^^^
loopback address

# I can connect from the same machine using telnet ..
# cannot connect from any remote machines.

loopback address is not accessible remotely

try using address of your network card.. (eg i tried mine at 10.2.10.123 and it works..)

kind regards -botp

Mat Schaffer

10/10/2007 5:24:00 AM

0



On Oct 9, 10:54 pm, Stephen Ware <sgw...@gmail.com> 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


Jon Lambert

10/10/2007 12:43:00 PM

0



> What am I missing?

You probably want..
server = TCPServer.new('0.0.0.0', 5056)

This will bind your server to all interfaces.


_________________________________________________________________
Help yourself to FREE treats served up daily at the Messenger Café. Stop by today.
http://www.cafemessenger.com/info/info_sweetstuff2.html?ocid=TXT_TAGLM_Oc...

Martin Portman

10/10/2007 2:41:00 PM

0

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.