示例#1
0
 /// <summary>
 /// 收到会话发来数据
 /// </summary>
 /// <param name="session">会话</param>
 /// <param name="buffer">收到的历史数据</param>
 protected sealed override void OnReceive(TelnetSession session, ReceiveStream buffer)
 {
     while (true)
     {
         var request = TelnetRequest.Parse(buffer);
         if (request == null)
         {
             break;
         }
         this.ExecTelnetRequest(session, request);
     }
 }
示例#2
0
        /// <summary>
        /// 从收到的数据流中解析请求体
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public static TelnetRequest Parse(ReceiveStream stream)
        {
            stream.Position = 0;
            var index = stream.IndexOf(Crlf); // 以CRLF为结束标识

            if (index < 0)
            {
                return(null);
            }
            var input = stream.ReadString(index, Encoding.ASCII);

            stream.Clear(index + Crlf.Length);

            if (string.IsNullOrWhiteSpace(input) == true) // 空内容
            {
                return(TelnetRequest.Parse(stream));
            }

            var items = input.Split(new string[] { " " }, 2, StringSplitOptions.RemoveEmptyEntries);
            var cmd   = items.First();
            var arg   = items.Length > 1 ? items.Last() : null;

            return(new TelnetRequest(cmd, arg));
        }