9 public class CorelinkTCP : ControlStream
13 private TcpClient tcpClient;
14 private string response = null;
15 private Thread clientReceiveThread;
17 private bool shouldExit;
19 private int MAX_BUF_SIZE = 65536;
20 private bool isTCPDone =
false;
22 private NetworkStream stream;
28 stream = tcpClient.GetStream();
33 StartTCPListenThread();
39 void StartTCPListenThread()
41 Debug.Log(
"StartTCPListenThread");
44 clientReceiveThread =
new Thread(
new ThreadStart(ListenForTCPData));
46 clientReceiveThread.Start();
50 Debug.Log(
"On client connect exception " + e);
63 throw new Exception(
"Timeout error");
65 string retval = response;
97 void ListenForTCPData()
105 bytes =
new Byte[MAX_BUF_SIZE];
112 while ((length = stream.Read(bytes, 0, bytes.Length)) != 0)
116 byte[] incomingData =
new byte[length];
117 Array.Copy(bytes, 0, incomingData, 0, length);
119 string serverMessage = Encoding.ASCII.GetString(incomingData);
121 response = serverMessage;
124 catch (
System.IO.IOException e)
126 Control.
Print(
"Catching IO Error from ending the stream and (hopefully) continuing");
132 catch (SocketException socketException)
134 Debug.LogException(socketException);
139 if (tcpClient == null)
148 NetworkStream stream = tcpClient.GetStream();
152 byte[] clientMessageAsByteArray = Encoding.ASCII.GetBytes(request);
154 stream.Write(clientMessageAsByteArray, 0, clientMessageAsByteArray.Length);
157 catch (SocketException socketException)
159 Debug.LogException(socketException);
160 throw new Exception(
"Socket exception: " + socketException);
CorelinkTCP(Config config)
override void stopConnection()
The Config class is filled once at the beginning of the unity session and contains important server i...
static int timeoutIterations
In some callbacks, the code is waiting on a response from the server. This specifies the number of 10...
override void sendMessage(string request)
static void Print(string message)
Singleton class to communicate with Corelink.