Ejemplo n.º 1
0
        void unup()
        {
            while (isok)
            {
                System.Threading.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();
                            str.command = Tokan;
                            str.date    = tempbtye;
                            receiveServerEvent(Tokan, str.date);

                            continue;
                        }
                        catch (Exception e)
                        {
                            if (ErrorMge != null)
                            {
                                ErrorMge(3, "unup:" + e.Message);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    if (ErrorMge != null)
                    {
                        ErrorMge(3, "unup:" + e.Message);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        void unup()
        {
            while (isok)
            {
                System.Threading.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);
_0x99:
                        if (tempbtye[0] == 0x99)
                        {
                            if (bytesRead > 1)
                            {
                                byte[] b = new byte[bytesRead - 1];
                                byte[] t = tempbtye;
                                Array.Copy(t, 1, b, 0, b.Length);
                                ListData[0] = b;
                                tempbtye    = b;
                                goto _0x99;
                            }
                            else
                            {
                                ListData.RemoveAt(0);
                                continue;
                            }
                        }

                        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
                                        {
                                            System.Threading.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)
                                {
                                    if (ErrorMge != null)
                                    {
                                        ErrorMge(3, e.StackTrace + "unup001:" + e.Message + "2 + a" + 2 + a + "---len" + len + "--tempbtye" + tempbtye.Length);
                                    }
                                }
                                try
                                {
                                    if (DT == DataType.json)
                                    {
                                        string   temp = System.Text.Encoding.UTF8.GetString(tempbtye, 2 + a, len);
                                        temppake str  = new temppake();
                                        str.command = tempbtye[0];
                                        str.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
                                            {
                                                receiveServerEvent(str.command, str.date);
                                                //receiveServerEvent.BeginInvoke(str.command, str.date, null, null);
                                                //System.Threading.ThreadPool.QueueUserWorkItem(new WaitCallback(rec), str);
                                                //receiveServerEvent(str.command, str.date);
                                                //    = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(rec));
                                                //tt.Start(str);
                                            }
                                        }
                                        else if (receiveServerEvent != null)
                                        {
                                            //
                                            // receiveServerEvent.BeginInvoke(str.command, str.date, null, null);
                                            receiveServerEvent?.Invoke(str.command, str.date);
                                            //System.Threading.ThreadPool.QueueUserWorkItem(new WaitCallback(rec), str);
                                            //System.Threading.Thread tt = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(rec));
                                            //tt.Start(str);
                                            // receiveServerEvent();
                                        }
                                    }
                                    if (DT == DataType.bytes)
                                    {
                                        // temp = System.Text.Encoding.UTF8.GetString(tempbtye, 2 + a, len);
                                        byte[] bs = new byte[len - 2 + a];
                                        Array.Copy(tempbtye, bs, bs.Length);
                                        temppake str = new temppake();
                                        str.command = tempbtye[0];
                                        str.datebit = bs;
                                        // receiveServerEvent.BeginInvoke(str.command, str.date, null, null);
                                        receiveServerEventbit?.Invoke(str.command, str.datebit);
                                    }
                                    continue;
                                }
                                catch (Exception e)
                                {
                                    if (ErrorMge != null)
                                    {
                                        ErrorMge(3, e.StackTrace + "unup122:" + e.Message);
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (tempbtye[0] == 0)
                            {
                                ListData.RemoveAt(0);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    if (ErrorMge != null)
                    {
                        ErrorMge(3, "unup:" + e.Message + "---" + e.StackTrace);
                    }
                    try
                    {
                        ListData.RemoveAt(0);
                    }
                    catch { }
                }
            }
        }
Ejemplo n.º 3
0
        void rec(object obj)
        {
            temppake str = obj as temppake;

            receiveServerEvent(str.command, str.date);
        }
Ejemplo n.º 4
0
        void unup()
        {
            while (isok)
            {
                System.Threading.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);
_0x99:
                        if (tempbtye[0] == 0x99)
                        {
                            if (bytesRead > 1)
                            {
                                byte[] b = new byte[bytesRead - 1];
                                byte[] t = tempbtye;
                                Array.Copy(t, 1, b, 0, b.Length);
                                ListData[i] = b;
                                tempbtye    = b;
                                goto _0x99;
                            }
                            else
                            {
                                ListData.RemoveAt(i);
                                continue;
                            }
                        }
labe881:
                        if (bytesRead > 2)
                        {
                            int a = tempbtye[1];
                            if (bytesRead > 2 + a)
                            {
                                String temp = System.Text.Encoding.UTF8.GetString(tempbtye, 2, a);
                                int    len  = 0;
                                try
                                {
                                    len = int.Parse(temp);
                                }
                                catch
                                { }
labered:
                                if ((len + 2 + a) > tempbtye.Length)
                                {
                                    ListData.RemoveAt(i);
                                    byte[] temps = new byte[tempbtye.Length];
                                    Array.Copy(tempbtye, temps, temps.Length);
                                    tempbtye = new byte[temps.Length + ListData[i].Length];
                                    Array.Copy(ListData[i], tempbtye, tempbtye.Length);

                                    goto labered;
                                }
                                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[i] = temps;
                                }
                                else if (tempbtye.Length == (len + 2 + a))
                                {
                                    ListData.RemoveAt(i);
                                }

                                temp = System.Text.Encoding.UTF8.GetString(tempbtye, 2 + a, len);
                                try
                                {
                                    temppake str = new temppake();
                                    str.command = tempbtye[0];
                                    str.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
                                        {
                                            receiveServerEvent(str.command, str.date);
                                            //receiveServerEvent.BeginInvoke(str.command, str.date, null, null);
                                            //System.Threading.ThreadPool.QueueUserWorkItem(new WaitCallback(rec), str);
                                            //receiveServerEvent(str.command, str.date);
                                            //    = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(rec));
                                            //tt.Start(str);
                                        }
                                    }
                                    else if (receiveServerEvent != null)
                                    {
                                        //
                                        if (receiveServerEvent != null)
                                        {
                                            // receiveServerEvent.BeginInvoke(str.command, str.date, null, null);
                                            receiveServerEvent(str.command, str.date);
                                        }
                                        //System.Threading.ThreadPool.QueueUserWorkItem(new WaitCallback(rec), str);
                                        //System.Threading.Thread tt = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(rec));
                                        //tt.Start(str);
                                        // receiveServerEvent();
                                    }
                                    continue;
                                }
                                catch (Exception e)
                                {
                                    if (ErrorMge != null)
                                    {
                                        ErrorMge(3, "unup:" + e.Message);
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    ListData.RemoveAt(0);
                    if (ErrorMge != null)
                    {
                        ErrorMge(3, "unup:" + e.Message);
                    }
                }
            }
        }