Beispiel #1
0
        /// <summary>
        /// 接受数据
        /// </summary>
        /// <param name="socket"></param>
        private void OnReceiveData(Socket socket)
        {
            byte[] tempArr = new byte[receLen];
            Array.Copy(buffer, tempArr, receLen);
            receiveDataList.AddRange(tempArr);
            if (receiveDataList.Count >= 4)
            {
                byte[] dataArray = receiveDataList.GetRange(0, 4).ToArray();
                //int len = BitConverter.ToInt32(dataArray, 0);
                int len = NetworkUtils.ByteArray2Int(dataArray, 0);
                //Debug.Log("receiveDataList: " + receiveDataList.Count+"  == ?"+len);
                if (receiveDataList.Count >= len)
                {
                    Package package = new Package();
                    package.UnPack(receiveDataList.ToArray());

                    EventData <Package> .CreateEvent(PackageDir.receive, package).Send();
                }
            }
        }