0
votes

I am developing an P2P application in Delphi XE5 with a PHP remote server as a tracker to make a list of the clients sockets. I am afraid that using UDP Hole Punching would fail at some point if client's NAT decides to close/block that random port it created with in the first message sent to the PHP remote server.

So I with to know How to make a more time persistent port configuration with NAT from the Client (which is written in Delphi). I do not want my user to need to know how to access a router and configure port forwarding himself.

Could I do that and use the server just to store the socket without the PHP-P-H and be sure that at least while the Delphi's application is running the port will remain opened?

If I do decide to use UDP hole punching from remote server, Will the NAT maintain the port opened to user's local PC if no other users connect to it directly (P2P) soon enough?

If I open that port with UDP, may I use TCP after?

Obs: Delphi XE5 to compile to Windows 32 and Android, so I need a non-Windows Only solution.

1
I just discovered that this I want is called UPNP. Therefore a component to deal with it should exist already.Please_Dont_Bully_Me_SO_Lords

1 Answers

2
votes

Microsoft has an API for working with NATs via uPNP, especially for assigning port mappings in particular. Look at the IUPnPNAT interface and its StaticPortMappingCollection property. Use IStaticPortMappingCollection.Add to assign ports in the NAT.

Of course, this only works with routers that have uPNP turned on. Not all routers support uPNP at all, or have uPNP enabled.