You are not logged in.

#1 2012-04-18 21:15:42

bjackman
Member
Registered: 2011-12-27
Posts: 32

Trying to allow connections on a certain port

I'm working on a small uni project where we have to write an instant messenger. It works fine on the Fedora computers in the school, but I'm trying to set it up at home so I can actually learn how this stuff works. I can start the server, which "binds" a socket to localhost:8090. I can connect to it by `telnet localhost 8090`, but I can't connect from another machine: telnet gives me "connection refused", and the actual client program throws an exception with a similar meaning. I can telnet to my computer on the default telnet port (where you get a login prompt), and I can also get responses on other computers from httpd running on mine.

I've done quit a lot of reading and it seems I might need to do something with `xinetd` to cause connections on port 8090 to reach my program - am I on the right lines? Perhaps I need to edit my `iptables.rules` (that seems unlikely since everything is currently allowed). Could anyone point me in the right direction?

ps: as I wrote this it occured to me that I might have a misunderstanding of what it means to "bind" a socket, in which case this is really a question about programming and doesn't belong here. Please let me know if you suspect this is the case!

Offline

#2 2012-04-18 23:39:33

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: Trying to allow connections on a certain port

bjackman wrote:

ps: as I wrote this it occured to me that I might have a misunderstanding of what it means to "bind" a socket

It sounds like a misunderstanding about binding... If your code is binding to localhost, then it will only accept connections made to the localhost address (127.0.0.1)... Trying to connect to that address on another computer will never reach your computer.

You should either bind to the wildcard address (0.0.0.0) which means it will accept connections to any valid address on your computer (ie 127.0.0.1 and/or 192.168.1.1 assuming your computer has the address 192.168.1.1), or bind to the specific non-loopback address (in my example, 192.168.1.1) in which case you will be able to connect from other computers, but to connect from the local computer, you will need to connect to the non-loopback address since it it not listening on the loopback.

Offline

#3 2012-04-19 17:55:28

bjackman
Member
Registered: 2011-12-27
Posts: 32

Re: Trying to allow connections on a certain port

Thank you very much. I've fixed it by `bind`ing to 0.0.0.0. Sorry my question didn't really belong here - I'll have to read up on socket programming I think!

edit: also

fukawi2 wrote:

You should either bind to the wildcard address (0.0.0.0) which means it will accept connections to any valid address on your computer (ie 127.0.0.1 and/or 192.168.1.1 assuming your computer has the address 192.168.1.1)

I found that when I `bind`ed to 0.0.0.0, the port would `accept` connections from remote machines as well as localhost. It also worked the way you suggested (`bind`ing to my external IP).

Last edited by bjackman (2012-04-19 18:12:32)

Offline

#4 2012-04-19 23:45:12

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: Trying to allow connections on a certain port

bjackman wrote:

I found that when I `bind`ed to 0.0.0.0, the port would `accept` connections from remote machines as well as localhost. It also worked the way you suggested (`bind`ing to my external IP).

Correct; 0.0.0.0 == Wildcard == All connections accepted (assuming firewall doesn't block it)

Offline

Board footer

Powered by FluxBB