• 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
Question by awesomeface · Sep 18, 2014 at 07:58 AM · javascriptnetworkingnetworkconnect

Connection to a registered host not working

 #pragma downcast
 var serverPort : int = 20000;
 var numberOfPlayers : int = 3;
 var numberOfConnections : int;
 var gameName : String = "Game Name";

 function Awake() {
     MasterServer.ClearHostList();
     }
 
 function Update () {
     }
 
 function OnGUI () {
     if(Network.peerType == NetworkPeerType.Disconnected){
         if(GUI.Button(Rect(0,90,100,30),"Refresh")){
             MasterServer.RequestHostList("GameTest");
             }
         serverPort = parseInt(GUI.TextField(Rect(0,30,100,30),serverPort.ToString()));
         numberOfPlayers = parseInt(GUI.TextField(Rect(0,60,100,30),numberOfPlayers.ToString()));
         gameName = GUI.TextField(Rect(0,0,100,30),gameName);
         if(gameName != ""){
             if(GUI.Button(Rect(0,120,100,30),"Create Server")){
                 Network.InitializeServer(numberOfPlayers,serverPort,!Network.HavePublicAddress());
                 MasterServer.RegisterHost("GameTest",gameName);
                 }
             }
         if (MasterServer.PollHostList().Length != 0) {
             var i : int = 0;
             var hostData: HostData[] = MasterServer.PollHostList();
             w$$anonymous$$le(i < hostData.Length){
                 GUI.Label(Rect(100,i*20,100,20),hostData[i].gameName);
                 GUI.Label(Rect(200,i*20,50,20),"[" + hostData[i].connectedPlayers.ToString() + "/" + hostData[i].playerLimit.ToString() + "]");
                 if(GUI.Button(Rect(250,i*20,100,20),"Connect")){
                     Network.Connect(hostData[i].ip,hostData[i].port);
                     }
                 i += 1;
                 }
             }
         }
     if(Network.isServer){
         numberOfConnections = Network.connections.Length;
         GUI.Label(Rect(0,0,100,30),numberOfConnections.ToString());
         }
     }
 
 function OnPlayerDisconnected(player: NetworkPlayer) {
     Network.RemoveRPCs(player);
     Network.DestroyPlayerObjects(player);
     }
 
 function OnDisconnectedFromServer() {
     Application.LoadLevel(0);
     }

The above code is from a script I titled "Menu", what I'm trying to accomplish is a simple server connect and create over the internet and whenever I try connecting to a server over the internet, the console gives me:

 Connected to master server at 67.225.180.24:23466

 Incoming host list query response from master server.

 Running as client. No player ID set yet.

UnityEngine.Network:Connect(String[], Int32) Menu:OnGUI() (at Assets/Menu.js:34)

But that's normal as when I connect over Lan it gives me that and even more, telling me all of the information about the server, but when I try to connect over the internet, it gives me (in addition to the ones above):

 The connection request to 124.187.118.95:60751 failed. Are you sure the server can be connected to?

What am I missing? Am I going about networking incorrectly? Someone help me please

Comment

People who like this

0 Show 0
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

Answer by basketballgames · Jul 23, 2019 at 03:34 AM

Thank you for the information. Great job, @.awesomeface .. ! atari breakout

Comment

People who like this

0 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

25 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can I connect to a server using the IP adress and the port with the new Unity 5 Networking API?? 0 Answers

Is it possible to send whole bytearray at once? JS 0 Answers

Network.Connect() never returns InvalidPassword 1 Answer

UnityScript not recognizing NetworkServer "Unknown Identifier" 0 Answers

Main Parameters of MP game for Clients to Join 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