Exemplo n.º 1
0
        /// <summary>
        ///     接收到信息的回调函数
        /// </summary>
        /// <param name="iar"></param>
        private void EndReceiveFromCallback(IAsyncResult iar)
        {
            int byteRead = 0;

            try
            {
                //完成接收
                byteRead = state.WorkSocket.EndReceiveFrom(iar, ref state.RemoteEP);
            }
            catch
            {
            }
            if (byteRead > 0)
            {
                state.IpEndPoint = (IPEndPoint)state.RemoteEP;
                byte[] haveDate = ReceiveDateOne.DateOneManage(state, byteRead); //接收完成之后对数组进行重置
                BeginReceiveFrom();
                int havePort = UdpPortSetGet.GetPort(ref haveDate);
                if (havePort != 0)
                {
                    state.IpEndPoint.Port = havePort;
                }
                StateCode statecode = ReceiveDateDistribution.Distribution(haveDate);
                codeManage(state, statecode);
            }
            else
            {
                BeginReceiveFrom();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     当Tcp收到数据全部在这里处理;也是数据的第一次处理
        /// </summary>
        /// <param name="stateOne">TcpState</param>
        /// <param name="reciverByte">数据</param>
        internal void TcpDateOne(TcpState stateOne, byte[] reciverByte)
        {
            stateOne.HeartTime = DateTime.Now;
            List <byte[]> listDate = StickPackage.DecryptPackage(reciverByte, ref stateOne.Residualpackage);

            foreach (var date in listDate)
            {
                StateCode statecode = ReceiveDateDistribution.Distribution(date);
                TcpCodeManage(stateOne, statecode);
            }
        }