/// <summary> /// Parses TcpMessage reply-stream /// </summary> /// <param name="stream">TcpMessage server reply-stream.</param> /// <returns>Returns parsed TcpMessage server reply-line.</returns> /// <exception cref="ArgumentNullException">Is raised when <b>line</b> is null reference.</exception> /// <exception cref="ParseException">Is raised when reply-line parsing fails.</exception> public static TcpReplyStream Parse(Stream stream) { if (stream == null) { throw new ArgumentNullException("stream"); } /* RFC 5321 4.2. * Reply-line = *( Reply-code "-" [ textstring ] CRLF ) * Reply-code [ SP textstring ] CRLF * * Since, in violation of this specification, the text is sometimes not sent, clients that do not * receive it SHOULD be prepared to process the code alone (with or without a trailing space character). */ TcpReplyStream reply = new TcpReplyStream(NetStream.EnsureNetStream(stream)); if (reply.ReplyCode <= 0) { throw new ParseException("Invalid TcpMessage server reply-stream '" + reply.ReplyCode.ToString() + "' reply-code."); } return(reply); }