Network.useNat Manual     Reference     Scripting  
Scripting > Runtime Classes > Network

static var useNat : bool


Should we use NAT punchthrough when connecting (client) or accepting connections (server)?

If this is set for a server only NAT punchthrough capable clients can connect to him but if the server has a NAT address this needs to be turned on for him to be connectable. Some routers do not know how to do NAT punchthrough so the only way for those users to host a game is to modify their routers so that the appropriate port is port forwarded (the game port). See the Network.TestConnection and Network.TestConnectionNAT for ways to detect how this could be automatically set for the enduser.

function OnGUI() {
if (GUILayout.Button ("Start Server"))
// Use NAT punchthrough if no public IP present
Network.useNat = !Network.HavePublicAddress();
Network.InitializeServer(32, 25002);
"JohnDoes game", "l33t game for all");