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 JBoy · Nov 06, 2012 at 09:54 AM · networkmasterserverconnectnothing

Network connection not working!

Hi everyone. I have created this script which is attached to an empty object in my scene. It uses the master server to connect. When I press the connect button it prints "yay" but doesn't connect. I am trying to connect to an executable (Mac) and the unity editor... Code:

 var serverPort : String="25000";
 var networkGameName : String;
 private var hostNumber : int;
 private var hostData: HostData[];
 
 function Start (){
     MasterServer.RequestHostList("GameType");
 }
 
 function Update (){
     if(MasterServer.PollHostList().length>0){
     hostData=MasterServer.PollHostList();
     print(hostData[0].gameName);
     }
 }
 
 function OnGUI (){ 
     if(Network.peerType == NetworkPeerType.Disconnected){
     networkGameName=GUI.TextField(Rect(5, 30, 150, 20), networkGameName, 20);
     if(GUI.Button(Rect(5, 5, 150, 20),"NewServer")){
         Network.InitializeServer(32, parseInt(serverPort), false);
         MasterServer.RegisterHost("GameType", networkGameName, "Comment");
     }
     
     if(GUI.Button(Rect(200, 40, 30, 20),"<") && hostNumber>0){
         hostNumber--;
     }
     if(GUI.Button(Rect(235, 40, 30, 20),">") && hostNumber<10){
         hostNumber++;
     }
     
     if(hostData){    
     for(var element : HostData in hostData) {
         var tmpIp : String = "";         
         tmpIp = element.ip[hostNumber] + " ";          
         Debug.Log(element.gameName + " ip: " + tmpIp + ":" + element.port);
         Network.natFacilitatorIP = tmpIp;
             Network.natFacilitatorPort = element.port;
     }  
     
     if(GUI.Button(Rect(200,5,200,30), hostData[hostNumber].gameName)){
         Network.Connect(tmpIp, hostData.port);
         print("yay");        
         }
     }else{
         GUI.Button(Rect(200,5,200,30), "Can't Find Any Games!");
     }
 }    
     if(Network.peerType != NetworkPeerType.Disconnected){
         if(GUI.Button(Rect(5, 5, 150, 20),"Disconnect")){
             Network.Disconnect();
         }
     }
 }   

-------------------Can you see anything wrong?--------------------

Comment
Add comment · Show 2
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
avatar image Daten · Nov 06, 2012 at 11:54 AM 0
Share

We need more information, What specifically is not happening, Is there any error messages, or any Network errors, Do you have port 2500 unblocked on both ends, in firewall and on the router? Are you trying it over local host or over IP, if IP Does it work over localhost?

avatar image Dreaded-Kane · Feb 23, 2013 at 09:42 PM 0
Share

I am having trouble connecting to servers and other people are having trouble connecting to my server. Does this mean we have to open the port on the router on both ends? This is not practical because the majority of users do not have capacity to do this, even I do not have access to the router in my house.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by gilmarhz · Nov 07, 2012 at 11:42 AM

MasterServer is to facilitate the connection. So, use it to connect.

This is the function:

static function Connect (hostData : HostData, password : String = "") : NetworkConnectionError

Just use the HostData: Network.Connect(HostData) like this:

 if(hostData){  

// for(var element : HostData in hostData) { // var tmpIp : String = "";
// tmpIp = element.ip[hostNumber] + " ";
// Debug.Log(element.gameName + " ip: " + tmpIp + ":" + element.port);

// Network.natFacilitatorIP = tmpIp; // Network.natFacilitatorPort = element.port; // }

 if(GUI.Button(Rect(200,5,200,30), hostData[hostNumber].gameName)){
    Network.Connect(hostData[hostNumber]);
    print("yay");     
    }

 }else{
    GUI.Button(Rect(200,5,200,30), "Can't Find Any Games!");
 }

And the code at Update() and Start, try to put it in a button or in a function called by a button, may be a button named Refresh:

 function RefreshHosts(){   
     MasterServer.RequestHostList("GameType");
 
     yield WaitForSeconds(1);
 
     if(MasterServer.PollHostList().length>0){  
         hostData=MasterServer.PollHostList(); 
         print(hostData[0].gameName); 
     }
 
 }
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
avatar image
1

Answer by gilmarhz · Nov 06, 2012 at 01:01 PM

Go to Edit/Project Settings/Network and set Debug Level to Full. Monitor on console what is happening when you connect() and you will get your answer. Remember to set Run In Background in Edit/Project Settings/Player because when you connect the client, the server is paused. If it does not connect, shows the console log here .

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

13 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

Related Questions

Network.Connect not connecting to host data or ip address 1 Answer

Unhandled message 65 from local ip. 0 Answers

Connection to a registered host not working 1 Answer

Clients are not disconnected when Master Server goes shut down 1 Answer

Can I Control a Network implemented by MasterServer ? 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