Search Unity

Network problem when building the game

Discussion in 'Editor & General Support' started by Lemon223, Feb 20, 2011.

  1. Lemon223

    Lemon223

    Joined:
    Nov 28, 2010
    Posts:
    11
    Hello,
    I'm working now for a few months in Unity and started a new project for a network/online game. I used the tutorial of M2H, and used a script of one of the example's and changed it a little bit and then builded it. Tested it with with a friend over the internet and it worked.

    I decided to expand it a little with a nice menu. builded it again, tested it over internet but now i'm getting an error :

    A client which was not in the connected player list disconnected. ???

    So i had a connection but disconnected immediately? i couldn't find anything that was cousing this error so i deleted all script exept the one that worked in the beginning tryed to build it and do it over internet but same error did it local but same error even in a new project with same starting script i'm getting this error and now even my other project (not over internet) gets this error?

    I can't find anything helpfull on the internet so if you could help.

    The code that I am using :

    Code (csharp):
    1. #pragma strict
    2. #pragma implicit
    3. #pragma downcast
    4.  
    5. var connectToIP : String = "127.0.0.1";
    6. var connectPort : int = 25001;
    7. var ConnectPassword : String = "";
    8.  
    9. function OnGUI ()
    10. {
    11.  
    12.     if (Network.peerType == NetworkPeerType.Disconnected){//hierdoor zie je dat je disconnected bent
    13.  
    14.         GUILayout.Label("Connection status: Disconnected");//hierdoor zie je dat je disconnected bent
    15.        
    16.         connectToIP = GUILayout.TextField(connectToIP, GUILayout.MinWidth(100)); // ip invullen
    17.         connectPort = parseInt(GUILayout.TextField(connectPort.ToString())); // port invullen
    18.         ConnectPassword = GUILayout.TextField(ConnectPassword, GUILayout.MinWidth(200));
    19.        
    20.         GUILayout.BeginVertical();
    21.                 if (GUILayout.Button ("Connect as client")) {//zorgt er voor dat je met de server connect
    22.                     Network.Connect(connectToIP, connectPort, ConnectPassword);} //connect met ingevulde ip en port
    23.                 //, ConnectPassword
    24.                 if (GUILayout.Button ("Start Server")){
    25.                     Network.incomingPassword = "HolyMoly";
    26.                     Network.InitializeServer(32, connectPort,false);}
    27.         GUILayout.EndVertical();
    28.        
    29.        
    30.     }else{//probeert connectie te maken
    31.         if (Network.peerType == NetworkPeerType.Connecting){
    32.             GUILayout.Label("Connection status: Connecting");
    33.            
    34.             // geconnected als client
    35.         } else if (Network.peerType == NetworkPeerType.Client){
    36.             GUILayout.Label("Connection status: Client!");
    37.             GUILayout.Label("Ping to server: "+Network.GetAveragePing(  Network.connections[0] ) );    
    38.            
    39.            
    40.             //je bent de server
    41.         } else if (Network.peerType == NetworkPeerType.Server){
    42.            
    43.             GUILayout.Label("Connection status: Server!");
    44.             GUILayout.Label("Connections: "+Network.connections.length);
    45.             if(Network.connections.length>=1){
    46.                 GUILayout.Label("Ping to first player: "+Network.GetAveragePing(  Network.connections[0] ) );
    47.             }          
    48.         }
    49.  
    50.         if (GUILayout.Button ("Disconnect")){
    51.             Network.Disconnect(200);}
    52.            
    53.     }
    54. }
    55.  
    56.  
    Thanks,

    Ruben,
     
    Last edited: Feb 20, 2011
  2. Lemon223

    Lemon223

    Joined:
    Nov 28, 2010
    Posts:
    11
    Nobody? i am still stuck i can't find the problem... thanks in advance ;)
     
  3. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,685
    did you set 'Application.runInBackground = true;' when you build the game ?
     
  4. U7Games

    U7Games

    Joined:
    May 21, 2011
    Posts:
    943
    i´m having the same problem , i will try appels´s suggest, but that must to be set on any script?.. or is the checkbox option in player inspector?=
     
  5. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,685
    call it in the awake of the first script that gets executed
     
  6. U7Games

    U7Games

    Joined:
    May 21, 2011
    Posts:
    943
    thanks!
     
  7. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    I have seen this a few times when testing Unity Networking as I follow Leepo's tutorials (http://forum.unity3d.com/threads/75385).

    I'm unclear what setting Application.runInBackground = true in Awake() will do if you've set that in player settings, as I assumed it was the same thing:

    http://unity3d.com/support/documentation/ScriptReference/Application-runInBackground.html
    "Should the player be running when the application is in the background?"

    http://unity3d.com/support/documentation/Components/class-PlayerSettings.html
    "Run in background Check this if you dont want to stop executing your game if it looses focus."
     
  8. U7Games

    U7Games

    Joined:
    May 21, 2011
    Posts:
    943
    yes!, i was meaning about the checkbox in player inspector when you build a webplayer... .. i haven´t tested yet but i guess i will be solved..
     
unityunity