- Home /
NetworkMessage Class for Error
Hey folks,
I'm trying to build a simple chat client / server setup as PoC for an greater networking project.
However, for that im using the NetworkServer simple with following initialisation code:
networkServer = new NetworkServerSimple();
networkServer.RegisterHandler (MsgType.Connect, OnClientConnected);
networkServer.RegisterHandler (MsgType.Disconnect, OnClientDisconnected);
networkServer.RegisterHandler (MsgType.Error, OnError);
networkServer.RegisterHandler (ChatID, OnChatMessage);
networkServer.Listen(port);
Debug.Log("host created:" + networkServer.serverHostId);
The Handler Methods are defined as followed:
private void OnClientConnected(NetworkMessage networkMessage)
{
Debug.Log("client connected");
}
private void OnClientDisconnected(NetworkMessage networkMessage)
{
Debug.Log("client disconnected");
}
private void OnError(NetworkMessage networkMessage)
{
}
My problem is the OnError-Handler. Each Handler has the NetworkMessage as parameter and I want to read that message in case of an error to display this error in my ui. But for that I need to know what Message the NetworkMessage is so I can read it correctly with
var msg = networkMessage.ReadMessage<???>()
Can anyone tell me the NetworkMessage class of MsgType.Error and maybe of the other two MsgTypes (Connect/Disconnect)?
Thanks in advance, Patrick
Answer by antonio-roberto · Oct 19, 2018 at 01:10 PM
private void OnError(NetworkMessage netMsg)
{
ErrorMessage errorMsg = new ErrorMessage();
errorMsg.Deserialize(netMsg.reader);
Debug.Log("errorCode = " + errorMsg.errorCode);
}
Your answer
Follow this Question
Related Questions
"Strange behaviour may occur" when using Network.AllocateViewID() 0 Answers
Choose Player UNet Problem with Client 0 Answers
Distribute terrain in zones 3 Answers
Unity Networking Errors 1 Answer