Timeout seems ridiculously flakey

Hi.

Just been having major issues with timeouts. I thought it was my project but it seems to be generally flakey. I’ve made two scripts below as a test:

Server:

using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
using UnityEngine.Networking.NetworkSystem;

public class Server : MonoBehaviour {
  
    public static int playerCount;
  
    public void Start()
    {
        if (NetworkServer.active)
        {
            Debug.LogError("Already Initialized");
            return;
        }
      
        // system msgs
        NetworkServer.RegisterHandler(MsgType.Connect, OnServerConnect);
        NetworkServer.RegisterHandler(MsgType.Disconnect, OnServerDisconnect);
        NetworkServer.RegisterHandler(MsgType.Error, OnServerError);
      
        NetworkServer.Listen(10000);
    }
  
    void OnServerConnect(NetworkMessage netMsg)
    {
        playerCount++;
        Debug.Log("Master received client");

    }
  
    void OnServerDisconnect(NetworkMessage netMsg)
    {
        playerCount--;
        Debug.LogError("Master lost client");
      
    }
  
    void OnServerError(NetworkMessage netMsg)
    {
        Debug.Log("ServerError from Master");
    }
  
  
}

Client:

using UnityEngine;
using System.Collections;
using UnityEngine.Networking;

public class Client : MonoBehaviour {
  
    public NetworkClient client;
  
    public void StartLobby()
    {
        client = new NetworkClient();
        client.RegisterHandler(MsgType.Connect, OnClientConnectPreGame);
        client.RegisterHandler(MsgType.Disconnect, OnClientDisconnectPreGame);
        client.RegisterHandler(MsgType.Error, OnClientErrorPreGame);
        client.Connect("192.168.1.100", 10000);
    }
  
    void Start()
    {
        StartLobby();
    }
  
    void OnClientConnectPreGame(NetworkMessage message)
    {
        Debug.Log("Connected");
        //ClientLobbyScreenManager.Instance.UpdateStatusText("Connected! Please Wait");
    }
  
    void OnClientDisconnectPreGame(NetworkMessage netMsg)
    {
        Debug.LogError("Client Disconnected from Master");
    }
  
    void OnClientErrorPreGame(NetworkMessage netMsg)
    {
        Debug.LogError("ClientError from Master");
    }
  
    void ServerReady(NetworkMessage netMsg)
    {
        Application.LoadLevel("GameClient");
      
        client.UnregisterHandler(MsgType.Connect);
        client.UnregisterHandler(MsgType.Disconnect);
        client.UnregisterHandler(MsgType.Error);
      
        // TODO: Register in game handlers
    }
  
  
  
  
}

I’m using a TP_Link router which can take 150 mbps a second. There’s definately a connection but about 10 seconds later a timeout occurs.

Any suggestions?

Thanks

1 Like

Did you try upping your Timeout values in the Network Manager? I’ve had a lot of issues with timeouts, I raised the values quiet a bit, now it’s much better even if not 100% stable.

With the standard settings it felt like every tiny disruption in the connection would result in a client timeout.

Can you point me to what values specfically?

Thanks

Hey Lukas,
sorry for the late reply.

I was referring to this:
http://docs.unity3d.com/ScriptReference/Networking.ConnectionConfig.html

Personally I’m using the NetworkManager, but I think you should be able to use this too.

It made it much better for me tweaking these settings in LAN, but in WLAN it was still very unreliable, I ended up implementing a reconnect feature for clients.

Hope that helps.