Пример #1
0
        /// <summary>
        /// This method is call when data was readed from the socket input buffer
        /// </summary>
        /// <param name="bytesRead"></param>
        /// <param name="readPacket"></param>
        private void OnDataReadCompletion(UInt32 bytesRead, DataReader readPacket)
        {
            if (readPacket == null)
            {
                if (Verbose)
                {
                    Debug.WriteLine("DataReader is null");
                }
            }
            else if (readPacket.UnconsumedBufferLength != 0)
            {
                Byte[] numArray = new Byte[bytesRead];
                readPacket.ReadBytes(numArray);
                ResponsePacket response = ParseResponse(numArray);

                if (response != null)
                {
                    DispatchResponse(response);

                    if (Verbose)
                    {
                        Debug.WriteLine("Nouveau message : {0}", BitConverter.ToString(response.ToArray()));
                    }
                }

                ReadBuffer(16);
            }
            else
            {
                if (OnDisconnection != null)
                {
                    OnDisconnection();
                }

                if (Verbose)
                {
                    Debug.WriteLine("Received zero bytes from the socket. Server must have closed the connection.");
                    Debug.WriteLine("Try disconnecting and reconnecting to the server");
                }
            }
        }