private AfterMsgHandleProcedure HandleDataRequestMessage(TCPMessage msg, TcpClient client, NetworkStream clientStream)
 {
     try
     {
         if (dataToSend.ContainsKey(msg.Info))
         {
             SendMessage(new TCPMessage()
             {
                 Type = TCPMessage.MsgType.Data, Info = msg.Info, PayLoad = dataToSend[msg.Info]
             }, clientStream);
         }
         else
         {
             //we don't have any entries for that tag send error back
             SendMessage(new TCPMessage()
             {
                 Type = TCPMessage.MsgType.Error, Info = "WrongDataTag", PayLoad = msg.Info
             }, clientStream);
         }
         return(AfterMsgHandleProcedure.KeepConnection);
     }
     catch (ObjectDisposedException)
     {
         //client dead
         return(AfterMsgHandleProcedure.CloseConnection);
     }
 }
        private AfterMsgHandleProcedure HandleTestMessage(TCPMessage msg, TcpClient client, NetworkStream clientStream)
        {
            UnityEngine.Debug.Log($"Recieved Message: {msg.Info}");

            ReplyTest(clientStream);

            return(AfterMsgHandleProcedure.KeepConnection);
        }
        protected void SendUnityClosedMessage(NetworkStream stream)
        {
            //inform
            TCPMessage msg = new TCPMessage()
            {
                Type = TCPMessage.MsgType.Error, Info = "UnityClosed", PayLoad = ""
            };

            SendMessage(msg, stream);
        }
 private AfterMsgHandleProcedure HandleDoneMessage(TCPMessage msg, TcpClient client, NetworkStream clientStream)
 {
     success = true;
     try
     {
         SendDoneMessage(clientStream);
         return(AfterMsgHandleProcedure.CloseConnection);
     }
     catch (ObjectDisposedException)
     { /*client already closed and we are done so we don't care if we can't send done back really*/
         return(AfterMsgHandleProcedure.CloseConnection);
     }
 }
 private AfterMsgHandleProcedure HandleErrorMessage(TCPMessage msg, TcpClient client, NetworkStream clientStream)
 {
     //TODO WTF DO I WANT TO KNOW FROM CLIENT ERROR MSGS?
     // I GUESS NOTHING JUST F**K OF INTO THE DISTANCE HAPPY?
     throw new NotImplementedException();
 }
 protected void SendMessage(TCPMessage msg, NetworkStream stream)
 {
     byte[] msgBuffer = Encoding.ASCII.GetBytes(msg.Stringify());
     stream.Write(msgBuffer, 0, msgBuffer.Length);
 }