- Home /
How connect client to server when ip is private ?
I'm a bit beginner in Unity networking (and networking...).
I have a server and a client, i want to my client connect to the server through internet (no local adresses so.).
I initialize my server with Network.InitializeServer(), and put useNat to true because the function HavePublicAdress() return me "false".
I connect my client with Network.Connect(), and put the externalIP and externalPort value of my server in parameters of this function.
My server starts okay, but for my client Unity said "The connection request failed", and the TestConnection() function return me "LimitedNATPunchtroughPortRestricted".
Did i miss something ? I think it's because of my private ip adress, but how to connect in this case ?
Thanks.
Answer by Dreamora · Jan 28, 2013 at 01:56 PM
You need to make it connect to a master server after initializing the server as you need NAT PunchThrough to connect from the outside, as this is handled and routed through the master server.
Without a master server you will have to force everyone who hosts games to setup UDP portforwards on his router and firewall.
A word of warning on this though: do better not rely on the inbuilt default addresses for masterserver, nat facilitator and connection tester as especially the nat facilitation on the UT servers are often not reachable and working. Also they are not for production use in any form so sooner or later you will be required to handle this yourself in some form.
The manual part of the documentation contains further information on the matter of the master server
Arggh... i was a bit afraid of "$$anonymous$$aster server" solution.
The fact is, i cant make my own master server (don't have the possibility), i dont want to pay a server and after all, i don't want this kind of "functionality" for the multiplayer part.
If i tell you that configure port into router and firewall is not a problem ? $$anonymous$$y goal is to have a system host/client like you can find on $$anonymous$$ecraft. A player host the game, give his ip and port adress to friends, and friends connect to him with his ip and port. No "master server", just a server on hoster machine.
Is there a solution to do this "simply" with my private ip (without master server) ? Or do i $$anonymous$$UST go on public adress for host something ?
In that case its no problem :) All you need to do is inform the user of the port they must forward (its the one you use to initialize the server) and tell them they need to forward UDP.
And on the client side the user then is required to provide the IP manually.
Technically if the hosters are required to port forward you could use a free website system and write a 'game listing service' using php on the server and WWW in unity to make games listable again without any cost involved.
Perfect thank you :) I guess my problem of "connection failed" is due to a closed port on my router so.
Thanks for your help :)
Answer by qabal · Dec 21, 2016 at 02:14 PM
"Without a master server you will have to force everyone who hosts games to setup UDP portforwards on his router and firewall" ...which still may not work because of your internet-provider NAT. So, even if you're writing simple two-person chat software you still need an outer server.