Exemple #1
0
 void Unup()
 {
     while (isok)
     {
         Thread.Sleep(10);
         try
         {
             int i     = 0;
             int count = ListData.Count;
             if (count > 0)
             {
                 int bytesRead = ListData[i] != null ? ListData[i].Length : 0;
                 if (bytesRead == 0)
                 {
                     continue;
                 }
                 byte[] tempbtye = new byte[bytesRead];
                 Array.Copy(ListData[i], tempbtye, tempbtye.Length);
                 try
                 {
                     ListData.RemoveAt(0);
                     Temppake str = new Temppake
                     {
                         command = Tokan,
                         date    = tempbtye
                     };
                     ReceiveServerEvent(Tokan, str.date);
                     continue;
                 }
                 catch (Exception e)
                 {
                     ErrorMge?.Invoke(3, "unup:" + e.Message);
                 }
             }
         }
         catch (Exception e)
         {
             ErrorMge?.Invoke(3, "unup:" + e.Message);
         }
     }
 }
Exemple #2
0
        void Rec(object obj)
        {
            Temppake str = obj as Temppake;

            ReceiveServerEvent(str.command, str.date);
        }
Exemple #3
0
        void Unup()
        {
            while (isok)
            {
                Thread.Sleep(10);
                try
                {
                    int count = ListData.Count;
                    if (count > 0)
                    {
                        int bytesRead = ListData[0] != null ? ListData[0].Length : 0;
                        if (bytesRead == 0)
                        {
                            continue;
                        }
                        byte[] tempbtye = new byte[bytesRead];
                        Array.Copy(ListData[0], tempbtye, tempbtye.Length);

                        if (bytesRead > 2)
                        {
                            int a = tempbtye[1];
                            if (bytesRead > 2 + a)
                            {
                                int len = 0;
                                if (DT == DataType.bytes)
                                {
                                    byte[] bb = new byte[a];
                                    Array.Copy(tempbtye, 2, bb, 0, a);
                                    len = ConvertToInt(bb);
                                }
                                else
                                {
                                    string temp = System.Text.Encoding.UTF8.GetString(tempbtye, 2, a);
                                    len = 0;
                                    try
                                    {
                                        len = int.Parse(temp);
                                        if (len == 0)
                                        {
                                            ListData.RemoveAt(0); continue;
                                        }
                                    }
                                    catch
                                    { }
                                }

                                try
                                {
                                    if ((len + 2 + a) > tempbtye.Length)
                                    {
                                        if (ListData.Count > 1)
                                        {
                                            ListData.RemoveAt(0);
                                            byte[] temps = new byte[ListData[0].Length];
                                            Array.Copy(ListData[0], temps, temps.Length);
                                            byte[] temps2 = new byte[tempbtye.Length + temps.Length];
                                            Array.Copy(tempbtye, 0, temps2, 0, tempbtye.Length);
                                            Array.Copy(temps, 0, temps2, tempbtye.Length, temps.Length);
                                            ListData[0] = temps2;
                                        }
                                        else
                                        {
                                            Thread.Sleep(20);
                                        }
                                        continue;
                                    }
                                    else if (tempbtye.Length > (len + 2 + a))
                                    {
                                        byte[] temps = new byte[tempbtye.Length - (len + 2 + a)];
                                        Array.Copy(tempbtye, (len + 2 + a), temps, 0, temps.Length);
                                        ListData[0] = temps;
                                    }
                                    else if (tempbtye.Length == (len + 2 + a))
                                    {
                                        ListData.RemoveAt(0);
                                    }
                                }
                                catch (Exception e)
                                {
                                    ErrorMge?.Invoke(3, e.StackTrace + "unup001:" + e.Message + "2 + a" + 2 + a + "---len" + len + "--tempbtye" + tempbtye.Length);
                                }
                                try
                                {
                                    if (len == 0)
                                    {
                                        ListData.RemoveAt(0);
                                        return;
                                    }
                                    if (DT == DataType.json)
                                    {
                                        string   temp = System.Text.Encoding.UTF8.GetString(tempbtye, 2 + a, len);
                                        Temppake str  = new Temppake
                                        {
                                            command = tempbtye[0],
                                            date    = temp
                                        };
                                        if (tempbtye[0] == 0xff)
                                        {
                                            if (temp.IndexOf("token") >= 0)
                                            {
                                                Tokan = temp.Split('|')[1];
                                            }
                                            else if (temp.IndexOf("jump") >= 0)
                                            {
                                                Tokan = "连接数量满";
                                                JumpServerEvent(temp.Split('|')[1]);
                                            }
                                            else
                                            {
                                                ThreadPool.QueueUserWorkItem(new WaitCallback(Rec), str);
                                            }
                                        }
                                        else if (ReceiveServerEvent != null)
                                        {
                                            ThreadPool.QueueUserWorkItem(new WaitCallback(Rec), str);
                                        }
                                    }
                                    if (DT == DataType.bytes)
                                    {
                                        byte[] bs = new byte[len - 2 + a];
                                        Array.Copy(tempbtye, bs, bs.Length);
                                        Temppake str = new Temppake
                                        {
                                            command = tempbtye[0],
                                            datebit = bs
                                        };
                                        ReceiveServerEvent.BeginInvoke(str.command, str.date, null, null);
                                    }
                                    continue;
                                }
                                catch (Exception e)
                                {
                                    ErrorMge?.Invoke(3, e.StackTrace + "unup122:" + e.Message);
                                }
                            }
                        }
                        else
                        {
                            ListData.RemoveAt(0);
                        }
                    }
                }
                catch (Exception e)
                {
                    ErrorMge?.Invoke(3, "unup:" + e.Message + "---" + e.StackTrace);
                    try
                    {
                        ListData.RemoveAt(0);
                    }
                    catch { }
                }
            }
        }