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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by $$anonymous$$ · May 03, 2013 at 01:04 PM · networking

Unity Networking, connecting to sever problems :(

Hey :):) So ive been following a tutorial and have this code as working progress for networking and when i build the game and have run in background on, nothing happens. On one game it says server initialized and then when i try to join the game on the other it wont allow me to. any ideas of what im doing wrong?

 var gameName: String ="Atomizer_Networking_Curtis";
 
 private var refreshing: boolean;
 private var hostData: HostData[];
 
 private var btnX: float;
 private var btnY: float;
 private var btnW: float;
 private var btnH: float;
 
 function Start(){
     btnX = Screen.width * 0.1;
     btnY = Screen.width * 0.1; 
     btnW = Screen.width * 0.1; 
     btnH = Screen.width * 0.1;
 } 
 
 function startServer(){
     Network.InitializeServer(4, 25001, !Network.HavePublicAddress);
     MasterServer.RegisterHost(gameName,"Tutorial Game Name","This is a tutorial game"); 
 }
 
 function refreshHostList(){
     MasterServer.RequestHostList(gameName);
     refreshing = true;
 
 }
 
 
 function Update(){
     if(refreshing){
         if(MasterServer.PollHostList().Length > 0){
             refreshing = false;
             Debug.Log(MasterServer.PollHostList().Length);
             hostData = MasterServer.PollHostList();
         }
     }
 }
 
 
 // Messages
 
 function OnServerInitialized(){
     Debug.Log("Server Initialized!");
 }
 
 function OnMasterServerEvent(mse:MasterServerEvent){
     if(mse == MasterServerEvent.RegistrationSucceeded){
         Debug.Log("Registered Server!");
     }
 }
 
 //GUI
 
 function OnGUI(){
     if(!Network.isClient && !Network.isServer){
         if(GUI.Button(Rect(btnX, btnY, btnW, btnH), "Start")){
             Debug.Log("Starting Server");
             startServer();
         }
     
         if(GUI.Button(Rect(btnX, btnY * 1.2 + btnH, btnW, btnH), "Refresh")){
             Debug.Log("Refreshing");
             refreshHostList();
         }    
         
         if(hostData){
             for(var i : int = 0; i < hostData.length; i ++ ){
                 if(GUI.Button(Rect(btnX * 1.5 + btnW, btnY * 1.2 + (btnH * i), btnW * 3, btnH * 0.5), hostData[i].gameName));
                     Network.Connect(hostData[i]);
             }
         }
     }
 }
Comment
Add comment · Show 5
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 FLASHDENMARK · May 03, 2013 at 01:56 PM 0
Share

Please format your code next time. It is done by selecting your code and pressing the "10101" button.

I have done it for you now, but I would like to stress the importance of doing so the next time.

avatar image Dave-Carlile · May 03, 2013 at 01:58 PM 0
Share

"It won't allow me to". There are a lot of things that could mean. What exactly happens when you try to join?

avatar image $$anonymous$$ · May 03, 2013 at 02:03 PM 0
Share

I play the build on one screen and run the server in the unity scene on the other (so running both) and go to join the server from the unity scene because im running the server off the build but it wont allow me to join any idea?

avatar image ByteSheep · May 03, 2013 at 02:23 PM 0
Share

You can add the following functions to the bottom of your script to get more info on what is going wrong when you try to connect.
Then check your console for errors and post back the results or do a google search.

 //Client functions called by Unity
 function OnConnectedToServer() {
     Debug.Log("This CLIENT has connected to a server");    
 }
 
 function OnDisconnectedFromServer(info : NetworkDisconnection) {
     Debug.Log("This SERVER OR CLIENT has disconnected from a server");
 }
 
 function OnFailedToConnect(error: NetworkConnectionError){
     Debug.Log("Could not connect to server: "+ error);
 }
 
 
 //Server functions called by Unity
 function OnPlayerConnected(player: NetworkPlayer) {
     Debug.Log("Player connected from: " + player.ipAddress +":" + player.port);
 }
 
 function OnServerInitialized() {
     Debug.Log("Server initialized and ready");
 }
 
 function OnPlayerDisconnected(player: NetworkPlayer) {
     Debug.Log("Player disconnected from: " + player.ipAddress+":" + player.port);
 }
 
 
 function OnFailedToConnectTo$$anonymous$$asterServer(info: NetworkConnectionError){
     Debug.Log("Could not connect to master server: "+ info);
 }
 
 function OnNetworkInstantiate (info : Network$$anonymous$$essageInfo) {
     Debug.Log("New object instantiated by " + info.sender);
 }
avatar image $$anonymous$$ · May 03, 2013 at 02:33 PM 0
Share

error says Failed to connect to 192.168.0.10:25001 because this system is already connected. This can occur when the network connection is disconnected too quickly for the remote system to receive the disconnect notification, for example when using Network.Disconnect(0).

comment says Could not connect to server: AlreadyConnectedToServer UnityEngine.Debug:Log(Object) Network$$anonymous$$anagerScript:OnFailedToConnect(NetworkConnectionError) (at Assets/Scripts/Network$$anonymous$$anagerScript.js:98)

1 Reply

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

Answer by ByteSheep · May 03, 2013 at 02:39 PM

http://forum.unity3d.com/threads/126170-Failed-ot-connect-because-this-system-is-already-connected

Your problem is most likely on line 69 in your code:

  if(GUI.Button(Rect(btnX * 1.5 + btnW, btnY * 1.2 + (btnH * i), btnW * 3, btnH * 0.5), hostData[i].gameName));

You have a semicolon at the end of the if statement, which means that Network.Connect is being called multiple times. Remove the semicolon from the end of that line.

Comment
Add comment · Show 3 · 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 $$anonymous$$ · May 03, 2013 at 02:50 PM 0
Share

Thankyou heaps :) didnt even notice, guess lack of sleep is kicking in anyway thankyou

avatar image ByteSheep · May 03, 2013 at 02:52 PM 0
Share

If it solved the error then please mark the answer as accepted by clicking the green arrow. Thank you.

avatar image $$anonymous$$ · May 03, 2013 at 03:05 PM 0
Share

if anyone else could, using the same code above, I have the characters spawning when you join the game but I want to have it so you can choose out of the two prefabs to use at the moment it just uses one, and i was wondering how you would do it so the player can choose

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

14 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

Related Questions

Multiple Cars not working 1 Answer

A node in a childnode? 1 Answer

UDP implementation in Unity, unable to send to two different machines 0 Answers

Make code execute for a specified time? 1 Answer

How to rotate 90 degrees 4 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