Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Simple socket server not working?

Reply
Thread Tools

Simple socket server not working?

 
 
Stephen Ware
Guest
Posts: n/a
 
      10-10-2007
(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/.

 
Reply With Quote
 
 
 
 
Stephen Ware
Guest
Posts: n/a
 
      10-10-2007
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/.

 
Reply With Quote
 
 
 
 
Stephen Ware
Guest
Posts: n/a
 
      10-10-2007
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/.

 
Reply With Quote
 
Peña, Botp
Guest
Posts: n/a
 
      10-10-2007
T24gQmVoYWxmIE9mIFN0ZXBoZW4gV2FyZToNCiMgc2VydmVyID 0gVENQU2VydmVyLm5ldygnMTI3
LjAuMC4xJywgNTA1NikNCiAgICAgICAgICAgICAgICAgICAgIC AgICBeXl5eXl5eXl5eDQogICAg
ICAgICAgICAgICAgICAgICAgICAgbG9vcGJhY2sgYWRkcmVzcw 0KDQojIEkgY2FuIGNvbm5lY3Qg
ZnJvbSB0aGUgc2FtZSBtYWNoaW5lIHVzaW5nIHRlbG5ldCAuLg 0KIyBjYW5ub3QgY29ubmVjdCBm
cm9tIGFueSByZW1vdGUgbWFjaGluZXMuDQoNCmxvb3BiYWNrIG FkZHJlc3MgaXMgbm90IGFjY2Vz
c2libGUgcmVtb3RlbHkNCg0KdHJ5IHVzaW5nIGFkZHJlc3Mgb2 YgeW91ciBuZXR3b3JrIGNhcmQu
LiAoZWcgaSB0cmllZCBtaW5lIGF0IDEwLjIuMTAuMTIzIGFuZC BpdCB3b3Jrcy4uKQ0KDQpraW5k
IHJlZ2FyZHMgLWJvdHANCg==

 
Reply With Quote
 
Mat Schaffer
Guest
Posts: n/a
 
      10-10-2007


On Oct 9, 10:54 pm, Stephen Ware <(E-Mail Removed)> 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


 
Reply With Quote
 
Ari Brown
Guest
Posts: n/a
 
      10-10-2007

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.



 
Reply With Quote
 
Jon Lambert
Guest
Posts: n/a
 
      10-10-2007


> What am I missing?


You probably want..
server =3D 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=E9. Stop =
by today.
http://www.cafemessenger.com/info/in...DTXT_TAGLM_Oc=
tWLtagline=

 
Reply With Quote
 
Martin Portman
Guest
Posts: n/a
 
      10-10-2007
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Steve Holden Python 1 02-03-2009 06:20 AM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Steve Holden Python 0 02-01-2009 12:45 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 0 02-01-2009 07:37 AM
socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 1 01-27-2009 05:05 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48,'Address already in use') Jean-Paul Calderone Python 0 01-27-2009 01:41 PM



Advertisments