示例#1
0
        internal void ReceiveCallback(IAsyncResult ar)
        {
            bool continueReceive = true;
            int  count           = 0;

            try
            {
                count = Socket.EndReceive(ar);
            }
            catch (SocketException)
            {
                OnConnectLost();
                return;
            }
            catch (Exception ex)
            {
                try
                {
                    OnErrorOccurred(ex);
                }
                catch { return; }
            }
            try
            {
                if (count == 0)
                {
                    return;
                }
                switch (ReceiveBuf[0])
                {
                case Consts.StringHeader:
                    continueReceive = OnCommandReceived(ReceiveBuf.ToFtString());
                    break;

                default:
                    throw new FormatException("Bad Header!");
                }
            }
            catch (Exception ex)
            {
                OnErrorOccurred(ex);
            }
            if (continueReceive)
            {
                BeginReceive();
            }
        }
示例#2
0
        internal string ReceiveString()
        {
            int count;

            try
            {
                count = Socket.EndReceive(BeginReceive());
            }
            catch (Exception)
            {
                OnConnectLost();
                throw;
            }
            if (count == 0)
            {
                return(null);
            }
            return(ReceiveBuf.ToFtString());
        }