// 接收服务端发来信息的方法
 static void Recv()
 {
     while (true)
     {
         while (Connected)
         {
             string requestString = PublicTools.DecodeMessage(stream);
             _messages.Add(requestString.Substring(0, 5), requestString.Substring(5));
         }
         while (!Connected)
         {
             LW.E("Message Recieve waiting for connection......");
             Thread.Sleep(500);
         }
     }
 }
        private static void Recv(object socketclientpara)
        {
            Socket        baseSocket        = socketclientpara as Socket;
            NetworkStream stream            = new NetworkStream(baseSocket);
            string        remoteEP          = baseSocket.RemoteEndPoint.ToString();
            bool          _connectionOpened = false;

            while (true)
            {
                try
                {
                    string requestString = PublicTools.DecodeMessage(stream);
                    LW.D("Recived Data: " + requestString);
                    if (requestString.Length <= 5)
                    {
                        baseSocket.CloseAndDispose();
                        break;
                    }

                    string _MessageId = requestString.Substring(0, 5);
                    requestString = requestString.Substring(5);

                    if (requestString == "openConnection")
                    {
                        LW.D("C: Recieve an OpenConnection Request, from " + remoteEP);
                        byte[] arrSendMsg = PublicTools.EncodeMessage(_MessageId, remoteEP);
                        stream.Write(arrSendMsg, 0, arrSendMsg.Length);
                        stream.Flush();
                        LW.D("C: Replied an OpenConnection Request, to " + remoteEP);
                        _connectionOpened = true;
                    }
                    else if (_connectionOpened)
                    {
                        if (requestString == "HeartBeat")
                        {
                            LW.D("B: Recieve a HearBeat, from " + remoteEP);
                            DateTime rtime      = DateTime.Now;
                            byte[]   arrSendMsg = PublicTools.EncodeMessage(_MessageId, rtime.ToNormalString());
                            stream.Write(arrSendMsg, 0, arrSendMsg.Length);
                            stream.Flush();
                            LW.D("C: Replied a HearBeat, to " + remoteEP);
                        }
                        else if (requestString.ToParsedObject(out DBInternal request))
                        {
                            QueryStrings[remoteEP] = requestString;
                            LW.D("Q: " + remoteEP + " :: " + requestString);
                            //It takes Time.....
                            string returnStr  = DatabaseCore.ProcessRequest(request);
                            byte[] arrSendMsg = PublicTools.EncodeMessage(_MessageId, returnStr);
                            stream.Write(arrSendMsg, 0, arrSendMsg.Length);
                            stream.Flush();
                            LW.D("P: " + remoteEP + " :: " + returnStr);
                        }
                        else
                        {
                            //Invalid Connection......
                            LW.E("E: " + remoteEP + " :: JSON Parse Exception!");
                            baseSocket.CloseAndDispose();
                            QueryStrings.Remove(remoteEP);
                            break;
                        }
                    }
                    else
                    {
                        LW.E("Connection to " + remoteEP + " is not marked as 'Opened'");
                        baseSocket.CloseAndDispose();
                        stream.CloseAndDispose();
                        QueryStrings.Remove(remoteEP);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    LW.E("Client " + remoteEP + " drops the connection. " + "\r\n" + ex.Message + "\r\n" + ex.StackTrace + "\r\n");
                    QueryStrings.Remove(remoteEP);
                    stream.CloseAndDispose();
                    baseSocket.CloseAndDispose();
                    break;
                }
            }
            QueryStrings.Remove(remoteEP);
            LW.E("Client Connection Socket to " + remoteEP + " gonna Stop!");
            Thread.CurrentThread.Abort();
            return;
        }