我需要使用特定命令查询网络打印机,然后我必须读取其状态字符串,该字符串以“ 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
}
}
}
}