TCP-Connection fails outside the local network

513 views
Skip to first unread message

chris #golang

unread,
Nov 19, 2011, 9:05:46 AM11/19/11
to golang-nuts
Hey there,
I wrote two network programs using the "net" package:

chris #golang

unread,
Nov 19, 2011, 9:14:30 AM11/19/11
to golang-nuts
Sorry for the stub before; my browser really wanted to send it before
it was finished :\

So here's the Problem:
My Server (a programm that listens for TCP-Connections;
net.AcceptTCP()) doesn't accept Connections from my Client
(net.DialTCP()) if both programs aren't in the same network (If they
are it works really fine); the connection fails due to a tiemeout.
The firewalls of both computers allow the connection, and I tested
both low ports (like http-port 80) and unused ones (like 2011).
I can't really believe that both pcs have to "unlock" the ports in
their router, especially if I use standard-Ports like the one for
http.
Where could the mistake hide?

Archos

unread,
Nov 19, 2011, 10:59:20 AM11/19/11
to golang-nuts
To be sure that there is no problem with your router/firewall/sytem,
try connect using this little great tool, netcat

http://nc110.sourceforge.net/

chris #golang

unread,
Nov 19, 2011, 2:31:11 PM11/19/11
to golang-nuts
Awesome tool, but it returns almost the same error. When my friend
listens with netcat:
D:\nc -vv -l -p 2011

and I try to connect by
D:\>nc -vv my.friend's.ip 2011

netcat can't establish a connection and returns a timeout:
muedsl-my-friend's-ip.citykom.de [my.friend's.ip] 2011 (?): TIMEDOUT
sent 0, rcvd 0: NOTSOCK

Both him and me allowed netcat everything it asked for; what's going
on?
icq, irc and other protocols work properly once they're authorized, so
where exactly is the difference?

Thanks so far,
chris.

Archos

unread,
Nov 19, 2011, 2:52:13 PM11/19/11
to golang-nuts
Are you sure that he has open that port in both *router and firewall*
(if is enabled on his system)?

You have in mind that to server whatever service, included http (port
80), you have to open it because they will be closed by default. Some
routers of ADSL/cable come with some ports open.

chris #golang

unread,
Nov 19, 2011, 3:14:15 PM11/19/11
to golang-nuts
Don't I open it by accepting Connection? And if not: How does e.g.
pidgin (for irc) open Ports? Or my Mailclient?

Archos

unread,
Nov 19, 2011, 4:23:46 PM11/19/11
to golang-nuts
In the server, in this case the computer of your friend, he has to run
a port scanner to know which ports has open. This is to checking the
firewall of her system.

He can use nmap; there are versions for windows too, and he has to run
it to level of localhost

http://nmap.org/

Archos

unread,
Nov 19, 2011, 4:26:05 PM11/19/11
to golang-nuts
And you, the client, can use it to scan its ports, so you can know
which ports he has open.

chris #golang

unread,
Nov 20, 2011, 7:07:47 AM11/20/11
to golang-nuts
I read a lot about ports and port-forwarding and solved my problem:
1. Told my router to forward the specified ports to my local address
2. Told my pc to use a static local ip address (DHCP's still running
for the other clients in the local network) for the port-forwarding to
work
3. Registered a dyndns so that peers don't always have to type in my
current ip-address

Thank you very much, now I get this whole port-stuff :)

chris

Reply all
Reply to author
Forward
0 new messages