1
\$\begingroup\$

I am trying to handle errors received by a UNET (new Unity3D networking) client. The below code successfully connects to a server when it is present, but obviously gives a timeout error when there is no server present.

I am trying to determine which type of error was received by the OnError callback method. MsgType is equal to MsgType.Error, which isn't specific, and all of the Read functions I have tried do not return valid data. At minimum I would like to be able to print the same error that prints to the debug log in a location the player can see it.

public class TestClient: MonoBehavior {

    private NetworkClient client;

    void Start () {
        client = new NetworkClient();
        client.Connect("127.0.0.1", 1234);
        client.RegisterHandler(MsgType.Error, OnError);
    }

    public void OnError(NetworkMessage netMsg) {

        //Read netMsg here somehow

        Debug.Log("Failed to connect to server");
    }
}

Note: This code is a retyped copy the working code, so there might be a typo or twenty. It also takes 15-30 seconds to throw the error (I didn't time it).

\$\endgroup\$
0
\$\begingroup\$

You must include read it as an ErrorMessage from the UnityEngine.Networking.NetworkSystem namespace.

netMsg.ReadMessage<ErrorMessage>();

http://forum.unity3d.com/threads/error-handling-in-unet.346525/

Note: It is amazing how fast you can find an answer AFTER posting to stackexchange.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .