简体   繁体   English

阅读器完成阅读整个消息后执行代码

[英]Execute code after reader has finished reading ENTIRE message

I would like to achieve the following result. 我想获得以下结果。 After the http message is fully read by the streamreader, I want to get the host of the request (which I don't think will be an issue) and start a tcp client to that host. 流阅读器完全读取http消息后,我想获取请求的主机(我认为这不是问题),并启动该主机的tcp客户端。

Code I currently have 我目前拥有的代码

Since the comment is in the while true loop it loops. 由于注释在while true循环中,因此它会循环。 But I thought readline() was blocking so it would only get executed once. 但是我认为readline()会阻塞,因此它只会执行一次。

Does anyone have any suggestions on how I could solve this matter? 有人对我如何解决此问题有任何建议吗?

Consider using the following code, to avoid redundancy (peeking the StreamReader to only then use the value). 考虑使用以下代码,以避免冗余(偷看StreamReader才使用该值)。 There are reports in this site of people having the same issue with Peek . 该站点有报道称Peek有着相同问题的人。

while ((line = reader.ReadLine()) != null)
{
    // Use the line
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM