void Update()
 {
     if (run)
     {
         if (tcpClient.receiveStatus)
         {
             tcpClient.receiveStatus = false;
             OnReceive(tcpClient.getData());
             tcpClient.Receive();
         }
         if (tcpClient.sendStatus)
         {
             tcpClient.sendStatus = false;
             OnSend(tcpClient.getSend());
         }
     }
     else if (!run && tcpClient.connectStatus)
     {
         run = true;
         tcpClient.Receive();
         OnConnect();
     }
     else if (!run && !tcpClient.connectStatus && start)
     {
         timer += Time.deltaTime;
         if (timer > timeout)
         {
             timer = 0;
             start = false;
             OnError();
         }
     }
 }
Esempio n. 2
0
 void Update()
 {
     if (run)
     {
         if (tcpClient.receiveStatus)
         {
             tcpClient.receiveStatus = false;
             string[] commands = tcpClient.getData().Split('\n');
             foreach (string cmd in commands)
             {
                 OnReceive(cmd);
             }
             tcpClient.Receive();
         }
         if (tcpClient.sendStatus)
         {
             tcpClient.sendStatus = false;
             OnSend(tcpClient.getSend());
         }
         if (!tcpClient.connectStatus)
         {
             OnDisconnect();
         }
     }
     else if (!run && tcpClient != null && tcpClient.connectStatus)
     {
         run = true;
         tcpClient.Receive();
         OnConnect();
     }
     else if (!run && tcpClient != null && !tcpClient.connectStatus && start)
     {
         timer += Time.deltaTime;
         if (timer > timeout)
         {
             timer = 0;
             start = false;
             OnError();
         }
     }
 }