Simple socket server not working?

S

Stephen Ware

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

Stephen Ware

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?
 
S

Stephen Ware

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

Peña, Botp

T24gQmVoYWxmIE9mIFN0ZXBoZW4gV2FyZToNCiMgc2VydmVyID0gVENQU2VydmVyLm5ldygnMTI3
LjAuMC4xJywgNTA1NikNCiAgICAgICAgICAgICAgICAgICAgICAgICBeXl5eXl5eXl5eDQogICAg
ICAgICAgICAgICAgICAgICAgICAgbG9vcGJhY2sgYWRkcmVzcw0KDQojIEkgY2FuIGNvbm5lY3Qg
ZnJvbSB0aGUgc2FtZSBtYWNoaW5lIHVzaW5nIHRlbG5ldCAuLg0KIyBjYW5ub3QgY29ubmVjdCBm
cm9tIGFueSByZW1vdGUgbWFjaGluZXMuDQoNCmxvb3BiYWNrIGFkZHJlc3MgaXMgbm90IGFjY2Vz
c2libGUgcmVtb3RlbHkNCg0KdHJ5IHVzaW5nIGFkZHJlc3Mgb2YgeW91ciBuZXR3b3JrIGNhcmQu
LiAoZWcgaSB0cmllZCBtaW5lIGF0IDEwLjIuMTAuMTIzIGFuZCBpdCB3b3Jrcy4uKQ0KDQpraW5k
IHJlZ2FyZHMgLWJvdHANCg==
 
M

Mat Schaffer

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
 
A

Ari Brown

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

Martin Portman

Stephen said:
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.
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top