Esempio n. 1
0
        private void ReceiveCallback(IAsyncResult asyncResult)
        {
            ReceiveCallbackState state = asyncResult.AsyncState as ReceiveCallbackState;

            try
            {
                state.Received = this.EndReceive(asyncResult);
            }
            catch (Exception e)
            {
                // an exception here means the connection closed
                this.HandleException(e);
                return;
            }

            // receiving 0 bytes means the socket has to be closed
            if (state.Received == 0)
            {
                this.ForcefullyDisconnect();
                this.FireOnConnectionLostHandler();
                return;
            }

            // queue the packets and process them
            this.mPacketizer.QueuePackets(state.Buffer, state.Received);
            this.mPacketizer.ProcessPackets();

            // if there is any pending to be processed pop it and call the receive callback
            this.FlushReceivingQueue();

            // begin receiving again
            this.BeginReceive(state.Buffer, this.mReceiveCallback);
        }
Esempio n. 2
0
        private void ReceiveCallback(IAsyncResult asyncResult)
        {
            ReceiveCallbackState state = asyncResult.AsyncState as ReceiveCallbackState;

            try
            {
                state.Received = this.EndReceive(asyncResult);
            }
            catch (Exception)
            {
                // an exception here means the connection closed
                return;
            }

            // queue the packets and process them
            this.mPacketizer.QueuePackets(state.Buffer, state.Received);
            this.mPacketizer.ProcessPackets();

            // if there is any pending to be processed pop it and call the receive callback
            this.FlushReceivingQueue();

            // begin receiving again
            this.BeginReceive(state.Buffer, this.mReceiveCallback);
        }