From b70fa177d1e029e9d99647cb1d92589f884621ae Mon Sep 17 00:00:00 2001 From: vis2k Date: Sun, 19 Aug 2018 18:29:20 +0200 Subject: [PATCH] Updated Telepathy to latest version. Fixes a bug where connect couldn't be called twice. --- .../Runtime/Telepathy/Client.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Unity-Technologies-networking/Runtime/Telepathy/Client.cs b/Unity-Technologies-networking/Runtime/Telepathy/Client.cs index 288516b25..5c92b2660 100644 --- a/Unity-Technologies-networking/Runtime/Telepathy/Client.cs +++ b/Unity-Technologies-networking/Runtime/Telepathy/Client.cs @@ -6,17 +6,19 @@ namespace Telepathy { public class Client : Common { - TcpClient client = new TcpClient(); + TcpClient client; Thread thread; public bool Connecting { - get { return thread != null && thread.IsAlive && !client.Connected; } + get { return thread != null && thread.IsAlive && + client != null && !client.Connected; } } public bool Connected { - get { return thread != null && thread.IsAlive && client.Connected; } + get { return thread != null && thread.IsAlive && + client != null && client.Connected; } } // the thread function @@ -59,6 +61,10 @@ public void Connect(string ip, int port) // not if already started if (Connecting || Connected) return; + // TcpClient can only be used once. need to create a new one each + // time. + client = new TcpClient(); + // clear old messages in queue, just to be sure that the caller // doesn't receive data from last time and gets out of sync. // -> calling this in Disconnect isn't smart because the caller may @@ -88,6 +94,7 @@ public void Disconnect() // (maybe it's Unity? maybe Mono?) client.GetStream().Close(); client.Close(); + client = null; } public bool Send(byte[] data)