Updated Telepathy to latest version. Fixes a bug where connect couldn't be called twice.

This commit is contained in:
vis2k 2018-08-19 18:29:20 +02:00
parent bafd9d1b28
commit b70fa177d1

View File

@ -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)