Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 解决粘包数据处理;也是数据的第一次处理
        /// </summary>
        /// <param name="stateOne">当前的连接属性</param>
        /// <param name="reciverByte">收到的数据</param>
        internal void UnpackStickyData(TcpTransmitBox stateOne, byte[] reciverByte)
        {
            //设置心跳包
            stateOne.HeartTime = DateTime.Now;
            //去掉粘包代码,得到数据集
            List <byte[]> listDate = StickPackage.DecryptPackage(reciverByte, ref stateOne.Residualpackage);

            foreach (byte[] date in listDate)
            {
                DataModel statecode = ReceiveData.DataValidation(date);
                CategorizeData(stateOne, statecode);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///     向服务器发送数据,最基础和原始的
        /// </summary>
        /// <param name="stateBase">StateBase</param>
        /// <param name="data">发送的数据</param>
        internal override void Send(StateBase stateBase, byte[] data)
        {
            if (stateBase == null)
            {
                return;
            }
            Socket handler = stateBase.WorkSocket;

            StickPackage.EncryptionPackage(ref data);
            try
            {
                handler.BeginSend(data, 0, data.Length, 0, SendCallback, handler);
            }
            catch
            {
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 向服务器发送数据,最基础和原始的
        /// </summary>
        /// <param name="stateBase">StateBase</param>
        /// <param name="data">发送的数据</param>
        override internal void Send(TransmitData stateBase, byte[] data) //实现客户端虚方法
        {
            if (stateBase == null)
            {
                return;
            }
            Socket handler = stateBase.WorkSocket;

            //对data数据进行粘包加密
            StickPackage.EncryptionPackage(ref data);
            try
            {
                //发送
                handler.BeginSend(data, 0, data.Length, 0, new AsyncCallback(SendCallback), handler);
            }
            catch
            {
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// 向客户端发送数据,最基础的发送
 /// </summary>
 /// <param name="stateBase">TcpState</param>
 /// <param name="data">发送的数据</param>
 override internal void Send(StateBase stateBase, byte[] data)
 {
     if (stateBase == null)
     {
         return;
     }
     StickPackage.EncryptionPackage(ref data);
     //MessageBox.Show(data.Length.ToString()+"你好"+data[9].ToString());
     try
     {
         stateBase.WorkSocket.BeginSend(data, 0, data.Length, 0, new AsyncCallback(SendCallback), stateBase);
     }
     catch (Exception Ex)
     {
         int i = Ex.Message.IndexOf("远程主机强迫关闭了一个现有的连接");
         if (i != -1)
         {
             TcpState stateOne = IPEndPointToState(stateBase.IpEndPoint);
             socketRemove(stateOne, Ex.Message);
         }
     }
 }