Jump to content
  • Advertisement
Sign in to follow this  
JohnnyCode

tcp remote connection

This topic is 3082 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello all, I have issue. I have a computer behind router, this computer listens as a server bound to pclocalip,2102 port. On the same computer I run a client that connects to (pc local ip, 2102 port). Connection is established this way. But if the client tries to connect to (router public ip,port 2102) address no connection is established, in other words, select() function on the server returns empty socket set always. I have even forwarded 2102 port on the router to the pc local ip. Select() returns always empty socket set. Also if I make the client connect to (router public ip,80) connection is established, but it does not matter wheather the server listens or is off. Also I have a question, does a router route 80 port data to all sub-ips, and on those sub-ip PCs, every server listening to 80 receives the income(multicast)?

Share this post


Link to post
Share on other sites
Advertisement
Did you actually try connecting to (router public ip, 2102) from a computer external to your network?
There is a good chance your router doesn't use the port forward table for connections that start inside the router.

Share this post


Link to post
Share on other sites
Specifically, the problem with trying to connect to your outside port from the inside is called "hairpin NAT" and is kind-of hit-and-miss. Many routers support it; many other routers don't. ("Hairpin" because the connection goes out, and then makes a very tight turn and comes right back in, just like a hairpin).

If you're doing matchmaking over the internet as well as locally, then possible mitigation includes using local broadcast to find locally hosted games, or sending both the public and the private address to the outside matchmaker, and trying both when connecting locally (although for 99% of all users, the local try will be a waste of time).

Share this post


Link to post
Share on other sites
you are right, thanks!

But I think I do not understand routing, or I will try to explain you my gesses.

Explicitly forwarded port to a local ip station does the job if you address public roiter ip with the set port.

Sending data to (public router,80) couses my server on local ip not receive any data to read (listens on 80). But it is becouse I established tcp connection to (public router,80) thus I am connected to router not to the local server behind it.

My gessing on how router would act was , that it will multicast data at 80 to all local ips, and on those local ips all servers that listens to 80 will have data to read on their sockets.

But I am not even connected to those local ips , so I gess thats why router is final station.

I wonder, is there a port assigned to every local ip , that router forwarded to this ip and does OS knows of this port? Those ports would be different for every ip.

Share this post


Link to post
Share on other sites
The router knows how to set everything else up because it does Network Address Translation(NAT). This NAT table is generated from your outgoing connections, and your port fowarding list (DMZ, UPnP, etc.).

You send an outgoing connection to www.google.com:80 asking for a web page.
Your computer sends out a packet from your local IP, and some random port.
Your router fowards this using your public IP and some other random port.
Google sends back the web page to your public IP and port, the router fowards these using the NAT table to your computer's IP and port.

If you don't have a port forward(or DMZ mode) for some port (say 22 for ssh.) then if I ssh your public IP, the router is going to say "i don't have an entry in my NAT table for that. connection denied". It isn't going to broadcast it on your network. It isn't going to send it anywhere. My ssh packets hit your router and die right there.

Share this post


Link to post
Share on other sites
Thanks KulSeran.

But TCP is so enigmatic.
My local station is not reachable publicly (unless I set router) but if this local station connects to a server , the server succesfully communicates back, thanks to NAT table.

But to connect to local station remotely is inpossible (unless I set router forwarding).

Thus I was thinking, if this "implicitly forwarded port for every local ip" existed it would save my day.

Doesn't such a port exist?

Or is there a way to "get public address for any local?".

I tried a public server that client connects to and have this server read sockaddr from this client socket, no avail. But if I was using UDP protocol, I would have to get corrrect client public address, for UDP server needs it for sendto() function.

Share this post


Link to post
Share on other sites
Quote:
Original post by JohnnyCode
Thus I was thinking, if this "implicitly forwarded port for every local ip" existed it would save my day.

Doesn't such a port exist?

Or is there a way to "get public address for any local?".

I tried a public server that client connects to and have this server read sockaddr from this client socket, no avail. But if I was using UDP protocol, I would have to get corrrect client public address, for UDP server needs it for sendto() function.
If you have two PCs behind a router, both listening on TCP port 1234, and someone connects to your public IP on TCP port 1234, what would happen? Both machines can't answer, the remote machine only has one TCP data stream.

There's NAT punch through for UDP and TCP (Although TCP is much more flakey), which would allow you to establish a connection with both machines behind a NAT, or if the router supports UPnP you could set up port forwarding from your app.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!