Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Studio Chat / NAT Punchthrough Possible ?

Author
Message
janbo
11
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 29th Dec 2019 13:04 Edited at: 29th Dec 2019 13:53
As the title says is "NAT Punchthrough Possible ?" in AGK
TCP_hole_punching Wikipedia

There are several threads about this topic.
Here are some but I'm sure I also missed some:
https://forum.thegamecreators.com/thread/197494
https://forum.thegamecreators.com/thread/224177
https://forum.thegamecreators.com/thread/217670

Maybe one can invoke an external script/programm to do this job ?
also maybe we can get Paul to take a look at it again
nonom
2
Years of Service
User Offline
Joined: 12th Nov 2017
Location: Aden
Posted: 29th Dec 2019 14:30 Edited at: 29th Dec 2019 14:30
janbo
11
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 29th Dec 2019 16:55 Edited at: 29th Dec 2019 17:55
Hm this is a very nice example if you want a to host a game on a php server.
I already have a system where one of the Clients is also the Host so it can run physic simulations and can decide if something is going wrong(cheating).
Can't do that in php, also in the current state it dosn't utilize UDP, for data that needs rapid updates, which I do.
Anyway I can't make out anything about portforwarding or TCP Hole Punching in there.
Do I miss something ?

Nontheless, big thanks nonom !
nonom
2
Years of Service
User Offline
Joined: 12th Nov 2017
Location: Aden
Posted: 29th Dec 2019 18:37
I meant a headless server without Apache or so, just using PHP in cli mode. Sockets are sockets no matters what language are you using nowadays, PHP is also a good choice like nodejs.

We need to separate concepts, I thought you want to move some logic from client to the server, but if you have solved this part client side; maybe you need something like a room system server side? like create/join/leave room where PHP or Nodejs will be enough so far. By other side saving a player position in redis is quite fast.

I'm my experiments with sockets they was working pretty fine with AGK.

//summon @MikeMax
janbo
11
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 29th Dec 2019 18:47 Edited at: 29th Dec 2019 18:47
The only problem is that one can't expect user/player to open a port on their router nowadays.
There is this method I read about alot which promises to solve the port problem called NAT Punchthrough.
You only need a Server in the WWW to match the clients to the hosting player.
One would send packages to each other at the same time (ip and port via the match Server)
and if an incomming message "hits" the outgoing message the outgoing port of the client should keep open...thats the theory I guess.

//also summoning MikeMax
nonom
2
Years of Service
User Offline
Joined: 12th Nov 2017
Location: Aden
Posted: 29th Dec 2019 19:39 Edited at: 29th Dec 2019 19:42
I think that your problem is solved opening the port that you are using. I had not problems with my experiments with Sockets in AGK. Was the thing which move me from Unity to AGK. And just using PHP. but It could be nodejs, java or whatever.

The player shouldn't noticed about needing to open any port.
smerf
15
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 30th Dec 2019 02:35
the solution to this is to deploy a server with the client. the server will launch when the client launches and run hidden. the client and sever send each other several messages on the lan on the desired port. the port will open thinking there is active communication between two clients. then the server is terminated and client connects out of open port to remote server.

Rick Nasher
2
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 3rd Jan 2020 18:08
@smerf: Wow, that sounds really nice if it works. Can you confirm you tried it out or is it theoretically?
smerf
15
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 3rd Jan 2020 20:30
I can break it down like this. there are public and private ips. went ten computers are connected to one router they all share one public IP address. if your server is not Port forwarded " or" it does not have universal plug-and-play setup in it's router or modem it will not be accessible. if a client connects to a remote server that is public or Port forwarded it should be a successful connection to the server. when the client initiates the connection they should send several messages with a time delay 400ms or so. the server in response should send several messages back before starting real comunication.
this gives a router time to figure out that there is active communication and to open the port for incoming information. with a Port forwarded server and that simple method of sending if you garbage messages you should have a hundred percent success rate. however if for some reason you cannot gain access to your router or modem for port forwarding or it does not support it. then you will use a true Nat punch-through. but in that punch it's very rare to have to use. in the case you cannot connect directly to a server that has been Port forwarded you will connect to a server that is port forwarded. this server will send the client and server each other's information. then the server and client will try to connect to each other several times in the blind until the ports open and they can talk. so the simple gist of it is if you port forward your server correctly and send a few messages from both sides there should be successful no matter what as long as the client initiates communication. Nat punch-through are not necessary unless you're doing with certain levels of security and encryption

Raven
14
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 4th Jan 2020 07:55
NAT Restrictions can occur either when a Port is already in usage, or when a Port is being Actively Blocked.
Typically speaking, nowadays most Routers used Port Triggering and Forwarding … this means that it'll Trigger the Activation of a Port based upon Demand, and should the Port not be "Whitelisted", it'll Automatically Forward it to the next Port available within the Range.

(Remember each Port can ONLY be used by a Single Connection / Device at any given time)

Now unique to all of this are Ports 80 (TCP Default) and 443 (UDP Default).
And these are what will be defaulted to, if the attempted Port Range fails... hence why you should always be monitoring Port 80 and 443.
Just keep in mind that these will be congested, with the potential to drop packets or have increased latency due to packet queues.

Another issue with these Ports is that, there's no way for the Router to know which Port it was originally SUPPOSED to be Sent / Received from.
The way that NAT "Punch-Through" works... is you setup Multiple Connections (typically 1 Per Client).
(which you ensure can actually initially connect and you're not entirely NAT Restricted)

In this regard, if a Port becomes unavailable; you can just switch to the next "Open" Connection.
Frankly a lot of these headache could easily be resolved with ISP switching to IPv6 Support., and it's somewhat ridiculous that most haven't yet.
Still, I do recall that IP Tunnelling can be another quite effective technique.
PSY
Valued Member
3
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 4th Jan 2020 17:27
@Raven

Hey,
thanks for the info. Haven't been tinkering with ports and stuff often, so your post came in quite handy

Q: Why could a lot of the issues you mentioned easily resolved with IPv6?


PSY


PSY LABS Games
Coders don't die, they just gosub without return
nonom
2
Years of Service
User Offline
Joined: 12th Nov 2017
Location: Aden
Posted: 4th Jan 2020 23:16
smerf wrote: "the solution to this is to deploy a server with the client. the server will launch when the client launches and run hidden. the client and sever send each other several messages on the lan on the desired port. the port will open thinking there is active communication between two clients. then the server is terminated and client connects out of open port to remote server."


A headless server build option would be awesome.
Ortu
DBPro Master
12
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 5th Jan 2020 17:21
Ipv6 doesn't need NAT, it has a large enough addressable range for every device to have a unique IP
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
PSY
Valued Member
3
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 6th Jan 2020 05:57
Ah, I see. Thanks Ortu


PSY LABS Games
Coders don't die, they just gosub without return
OrangeTEK
User Offline
Joined: 7th Aug 2019
Location:
Posted: 2nd Feb 2020 21:39
This is best done with connection-less protocols like udp. https://en.wikipedia.org/wiki/UDP_hole_punching
I have done this in purebasic. As i am new to AppGameKit, i might give it a go as a first project and post the source.
janbo
11
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 3rd Feb 2020 21:17
Yes Please
smerf
15
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 4th Feb 2020 01:57
turns out its stupid easy client just sends a dummy message then server redponds. thats it. servers second response to a clients second message is allowed through a firewall.

OrangeTEK
User Offline
Joined: 7th Aug 2019
Location:
Posted: 5th Feb 2020 06:32 Edited at: 5th Feb 2020 06:36
You need a STUN server where clients connect first. The STUN server collects the public ip addresses of clients and sends them to each client. From there its like smurf said.

https://www.3cx.com/pbx/what-is-a-stun-server/
nonom
2
Years of Service
User Offline
Joined: 12th Nov 2017
Location: Aden
Posted: 13th Feb 2020 13:56
Using Sockets should be a good choice

Login to post a reply

Server time is: 2020-02-26 07:59:53
Your offset time is: 2020-02-26 07:59:53