如何读取TCPStream直到出现新行或超时

时间:2018-10-11 15:10:55

标签: c# inputstream tcpclient

我需要使用特定命令查询网络打印机,然后我必须读取其状态字符串,该字符串以“ new line” char分隔。

如何从TCPClient流中读取消息,直到定义的分隔符(新行\ n)或超时?

                using (TcpClient client = new TcpClient())
                {
                    using (NetworkStream networkStream = client.GetStream())
                    {
                        using (BinaryWriter writer = new BinaryWriter(networkStream))
                        {
                            writer.Write(GETSTATUS_QUERY_STRING);

                            using (BinaryReader reader = new BinaryReader(networkStream))
                            {
                                 //GET STATUS untile new line or timeout
                            }
                        }
                    }
                }

0 个答案:

没有答案