- Home /
Error: "A client which was not in the connected player list disconnected. ???"
Hi,
I have two locally connected applications, one being the server, the other being the client. It always worked with my differents builds but this time I have the strangest error:
I don't have any messages in the console saying that a player has connected/disconnected, I only have "Server created" and this error. I should say that both applications works perfectly independently ...
Here's my code:
Server:
using UnityEngine;
using System.Collections;
using System.Diagnostics;
using UnityEngine.UI;
public class ServerPropsMVR : MonoBehaviour {
/* VARIABLES */
int nbClient = 5;
int nbPort = 25000;
bool useNat = false;
public Text connexionStatusText;
int playerCount;
/* INITIALISATION */
void Start (){
playerCount = 0;
Network.InitializeServer (nbClient,nbPort,useNat);
Process.Start("MVR_Oculus_AsClient");
}
/* MESSAGES */
void OnServerInitialized () {
UnityEngine.Debug.Log ("Server created");
}
void OnPlayerConnected () {
UnityEngine.Debug.Log ("Client connected");
playerCount++;
if (playerCount > 0) {
connexionStatusText.text = "Connected";
connexionStatusText.color = Color.green;
}
}
void OnPlayerDisconnected () {
UnityEngine.Debug.Log ("Client disconnected");
playerCount--;
if (playerCount < 1) {
connexionStatusText.text = "Disconnected";
connexionStatusText.color = Color.red;
}
}
}
Client:
using UnityEngine;
using System.Collections;
public class ClientPropsMVR : MonoBehaviour {
// Server properties
string serverIP = "127.0.0.1";
int serverPort = 25000;
/* INITIALISATION */
void Update(){
if (Network.peerType == NetworkPeerType.Disconnected)
Network.Connect(serverIP, serverPort);
}
/* MESSAGES */
void OnConnectedToServer () {
Debug.Log ("Connected to server");
}
void OnApplicationQuit () {
Network.Disconnect (200);
}
}
Answer by Cheryl_Dwyer · Nov 01, 2015 at 11:00 PM
Well, this is quite an old post, and you've probably figured it out already, but I'll write this anyway. This exception, as the error states, is thrown when a player who's not in the connected player list disconnects - so the question is why that player was not in the list. From my experience, this occurs when a client connects and then disconnects again in the same frame (probably before the server has time to add them), so check any methods called once a frame (like Update() and so on) for Network.Disconnect() or Network.CloseConnection(). Also, you don't need to keep track of the player count yourself. Unity keeps a list of all the connected NetworkPlayers, so you can get the number of players by checking the list's length : Network.connections.Length. Hope this helped!
Hey man, thanks for the answer ! A bit late indeed, i moved to another project and Unity changed its network system meanwhile ... but anyway i'll keep it in $$anonymous$$d next time ! Cheers
Your answer
![](https://koobas.hobune.stream/wayback/20220613193248im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Time problem with Joining to Multilayer game 1 Answer
Unity Networking - Clients scattered around scenes 0 Answers
OnConnectedToServer not working 1 Answer
Can anyone help me with my network script? 1 Answer
Node.js Problem 1 Answer