Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Daniel 6 · Oct 01, 2010 at 10:18 PM · networkingconnection

Network connection problem

I'm trying to connect two machines together. I know that I can't just connect immediately without doing some testing beforehand, like for NAT. I got this script from the Unity documentation. I think it's supposed to determine if NAT should be used or not, but some parts look a little messed up to me:

1) The line that says "case ConnectionTesterStatus.NATpuchthroughAddressRestrictedCone:" doesn't execute any code. 2) There are 2 case's that say "ConnectionTesterStatus.LimitedNATPunchthroughPortRestricted:"

As of right now I am unable to establish a connection with this script. Are there any network experts that can fix this script up for me so I can actually make a simple connection?

var testStatus = "Testing network connection capabilities."; var testMessage = "Test in progress"; var shouldEnableNatMessage : String = ""; var doneTesting = false; var probingPublicIP = false; var serverPort = 9999; var connectionTestResult = ConnectionTesterStatus.Undetermined;

// Indicates if the useNat parameter be enabled when starting a server var useNat = false;

function OnGUI() { GUILayout.Label("Current Status: " + testStatus); GUILayout.Label("Test result : " + testMessage); GUILayout.Label(shouldEnableNatMessage); if (!doneTesting) TestConnection(); }

function TestConnection() { // Start/Poll the connection test, report the results in a label and // react to the results accordingly connectionTestResult = Network.TestConnection(); switch (connectionTestResult) { case ConnectionTesterStatus.Error: testMessage = "Problem determining NAT capabilities"; doneTesting = true; break;

     case ConnectionTesterStatus.Undetermined: 
         testMessage = "Undetermined NAT capabilities";
         doneTesting = false;
         break;

     case ConnectionTesterStatus.PublicIPIsConnectable:
         testMessage = "Directly connectable public IP address.";
         useNat = false;
         doneTesting = true;
         break;

     // This case is a bit special as we now need to check if we can 
     // circumvent the blocking by using NAT punchthrough
     case ConnectionTesterStatus.PublicIPPortBlocked:
         testMessage = "Non-connectble public IP address (port " + 
             serverPort +" blocked), running a server is impossible.";
         useNat = false;
         // If no NAT punchthrough test has been performed on this public 
         // IP, force a test
         if (!probingPublicIP) {
             connectionTestResult = Network.TestConnectionNAT();
             probingPublicIP = true;
             testStatus = "Testing if blocked public IP can be circumvented";
             timer = Time.time + 10;
         }
         // NAT punchthrough test was performed but we still get blocked
         else if (Time.time > timer) {
             probingPublicIP = false;         // reset
             useNat = true;
             doneTesting = true;
         }
         break;
     case ConnectionTesterStatus.PublicIPNoServerStarted:
         testMessage = "Public IP address but server not initialized, "+
             "it must be started to check server accessibility. Restart "+
             "connection test when ready.";
         break;

     case ConnectionTesterStatus.LimitedNATPunchthroughPortRestricted:
         testMessage = "Limited NAT punchthrough capabilities. Cannot "+
             "connect to all types of NAT servers.";
         useNat = true;
         doneTesting = true;
         break;

     case ConnectionTesterStatus.LimitedNATPunchthroughPortRestricted:
         testMessage = "Limited NAT punchthrough capabilities. Cannot "+
             "connect to all types of NAT servers. Running a server "+
             "is ill advised as not everyone can connect.";
         useNat = true;
         doneTesting = true;
         break;

     case ConnectionTesterStatus.LimitedNATPunchthroughSymmetric:
         testMessage = "Limited NAT punchthrough capabilities. Cannot "+
             "connect to all types of NAT servers. Running a server "+
             "is ill advised as not everyone can connect.";
         useNat = true;
         doneTesting = true;
         break;

     case ConnectionTesterStatus.NATpunchthroughAddressRestrictedCone:
     case ConnectionTesterStatus.NATpunchthroughFullCone:
         testMessage = "NAT punchthrough capable. Can connect to all "+
             "servers and receive connections from all clients. Enabling "+
             "NAT punchthrough functionality.";
         useNat = true;
         doneTesting = true;
         break;

     default: 
         testMessage = "Error in test routine, got " + connectionTestResult;
 }
 if (doneTesting) {
     if (useNat)
         shouldEnableNatMessage = "When starting a server the NAT "+
             "punchthrough feature should be enabled (useNat parameter)";
     else
         shouldEnableNatMessage = "NAT punchthrough not needed";
     testStatus = "Done testing";
 }

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by ClandestineMan · Oct 11, 2010 at 08:14 PM

To answer your first question about the "case ConnectionTesterStatus.NATpunchthroughAddressRestrictedCone:" line... it actually is running code. Its running the code below it. So in the case of the case statement there is no break statement to get out so it keeps on going through the next case statement. So, it is doing the ConnectionTesterStatus.NATpunchthroughFullCone code.

As for the second question, I think its the case of copy/paste error. Both sets of code are pretty much doing the same thing.

This script is only testing network capability. There is no code setting up a server and no code connecting to a server. Is there more code to look at?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Networking problems 2 Answers

NetworkMatch.DropConnection not executing callback 0 Answers

Client Disconnect with message “Peer Created” - PUN 0 Answers

How to make host unavailable - Unity Networking 1 Answer

Network.Instantiate missing reference exception 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges