Пример #1
0
        /// <summary>
        /// 执行数据解析处理
        /// </summary>
        /// <param name="arrMsgRec">接收到的数组</param>
        /// <param name="length">数组有效长度</param>
        private void execDataProc(byte[] arrMsgRec, int length)
        {
            //if(++recIndex == 20) {
            //    ProcessData(null);
            //    recIndex = 0;

            //}
            //return;
            SerializationUnit seru = new DataDisplay.SerializationUnit();
            StructData        ms   = new StructData();

            byte[] destinationArray = new byte[length];
            Array.Copy(arrMsgRec, destinationArray, length);
            List <byte[]> lstrec = execDataStick(destinationArray);

            foreach (byte[] destinationArr in lstrec)
            {
                try {
                    StructData mst = (StructData)seru.DeserializeObject(destinationArr);
                    if (mst.datamain != null)
                    {
                        if (mst.datamain.Length > 0)
                        {
                            //对获取的数据进行逻辑处理
                            ProcessData(mst);
                        }
                    }
                } catch (Exception e) {
                    Debug.Write(e.Message);
                    Array.Clear(s2, 0, s2.Length);
                }
            }
        }
Пример #2
0
        private void ReceiveCallBack(IAsyncResult ar)
        {
            try {
                int REnd = m_clientSocket.EndReceive(ar);
                //string strReceiveData = Encoding.Unicode.GetString(m_receiveBuffer,0,REnd);


                SerializationUnit seru             = new DataDisplay.SerializationUnit();
                StructData        ms               = new StructData();
                byte[]            destinationArray = new byte[REnd];
                Array.Copy(m_receiveBuffer, destinationArray, REnd);
                List <byte[]> lstrec = execDataStick(destinationArray);
                foreach (byte[] destinationArr in lstrec)
                {
                    try {
                        StructData mst = (StructData)seru.DeserializeObject(destinationArr);
                        if (mst.datamain != null)
                        {
                            if (mst.datamain.Length > 0)
                            {
                                //对获取的数据进行逻辑处理
                                ProcessData(mst);
                            }
                        }
                    } catch (Exception e) {
                        Debug.Write(e.Message);
                        Array.Clear(s2, 0, s2.Length);
                        s2 = new byte[0];
                    }
                }

                //    byte[] destinationArray = new byte[REnd];

                //    //  byte[] destinationArray1 = new byte[length];

                //    Array.Copy(m_receiveBuffer, destinationArray, REnd);
                //this.Invoke((Action)delegate ()
                //{
                //    lstBuff.Remove(destinationArray);
                //}
                //);


                m_clientSocket.BeginReceive(m_receiveBuffer, 0, m_receiveBuffer.Length, 0, new AsyncCallback(ReceiveCallBack), null);
            } catch (Exception ex) {
            }
        }