Ejemplo n.º 1
0
        private void ReceiveCallBack(IAsyncResult ar)
        {
            bool isError = false;

            try
            {
                int len = client.EndReceive(ar);
                if (len == 0)
                {
                    isError = true;
                    if (socketEvent != null)
                    {
                        socketEvent.ReceiveFailEvent(this);
                    }
                    return;
                }
                byte[] newMsgArr = new byte[len];
                Buffer.BlockCopy(msgArr, 0, newMsgArr, 0, len);

                DataPack.AddMsg(newMsgArr);
                if (socketEvent != null)
                {
                    socketEvent.ReceiveSuccessEvent(this);
                }
            }
            catch (Exception e)
            {
                LogManger.Instance.Error(e);
                isError = true;
                if (socketEvent != null)
                {
                    socketEvent.ReceiveFailEvent(this);
                }
            }
            finally
            {
                if (isError)
                {
                    Disconnect();
                }
                else
                {
                    BeginReceive();
                }
            }
        }