From 4f89f8182b6703315d491d7ad9cd2e36824d319e Mon Sep 17 00:00:00 2001 From: vis2k Date: Wed, 22 Aug 2018 21:37:12 +0200 Subject: [PATCH] LLAPITransport receive: don't return if error != 0 because it's part of the disconnect message. fixes a bug where disconnect wasn never received on client/server. --- .../Runtime/Transport/LLAPITransport.cs | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Unity-Technologies-networking/Runtime/Transport/LLAPITransport.cs b/Unity-Technologies-networking/Runtime/Transport/LLAPITransport.cs index 5c529aa5e..5a3e751cc 100644 --- a/Unity-Technologies-networking/Runtime/Transport/LLAPITransport.cs +++ b/Unity-Technologies-networking/Runtime/Transport/LLAPITransport.cs @@ -108,11 +108,16 @@ public bool ClientGetNextMessage(out TransportEvent transportEvent, out byte[] d int receivedSize; NetworkEventType networkEvent = NetworkTransport.ReceiveFromHost(clientId, out connectionId, out channel, clientReceiveBuffer, clientReceiveBuffer.Length, out receivedSize, out error); - NetworkError networkError = (NetworkError) error; + // note: 'error' is used for extra information, e.g. the reason for + // a disconnect. we don't necessarily have to throw an error if + // error != 0. but let's log it for easier debugging. + // + // DO NOT return after error != 0. otherwise Disconnect won't be + // registered. + NetworkError networkError = (NetworkError)error; if (networkError != NetworkError.Ok) { - Debug.LogError("NetworkTransport.Receive failed: hostid=" + clientId + " connId=" + connectionId + " channelId=" + channel + " error=" + networkError); - return false; + Debug.Log("NetworkTransport.Receive failed: hostid=" + clientId + " connId=" + connectionId + " channelId=" + channel + " error=" + networkError); } switch (networkEvent) @@ -186,11 +191,16 @@ public bool ServerGetNextMessage(out int connectionId, out TransportEvent transp int receivedSize; NetworkEventType networkEvent = NetworkTransport.ReceiveFromHost(serverHostId, out connectionId, out channel, serverReceiveBuffer, serverReceiveBuffer.Length, out receivedSize, out error); + // note: 'error' is used for extra information, e.g. the reason for + // a disconnect. we don't necessarily have to throw an error if + // error != 0. but let's log it for easier debugging. + // + // DO NOT return after error != 0. otherwise Disconnect won't be + // registered. NetworkError networkError = (NetworkError)error; if (networkError != NetworkError.Ok) { - Debug.LogError("NetworkTransport.Receive failed: hostid=" + serverHostId + " connId=" + connectionId + " channelId=" + channel + " error=" + networkError); - return false; + Debug.Log("NetworkTransport.Receive failed: hostid=" + serverHostId + " connId=" + connectionId + " channelId=" + channel + " error=" + networkError); } // LLAPI client sends keep alive messages (75-6C-6C) on channel=110.