0

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.

Code I currently have

Since the comment is in the while true loop it loops. But I thought readline() was blocking so it would only get executed once.

Does anyone have any suggestions on how I could solve this matter?

juser
  • 13
  • 4

1 Answers1

0

Consider using the following code, to avoid redundancy (peeking the StreamReader to only then use the value). There are reports in this site of people having the same issue with Peek.

while ((line = reader.ReadLine()) != null)
{
    // Use the line
}
fhcimolin
  • 616
  • 1
  • 8
  • 27
  • @fhcimiolin but then inside that while loop i would only have a partial message, I want to be "notified" when the whole message has been received – juser Mar 07 '19 at 10:12
  • @juser But `ReadLine` does essentially that - it reads the next line and assigns it to `line`, for you to use inside the loop. When the whole message has been received, that is - when all the lines have been read, then the while loop is exited and you can proceed. That is just the 'usual way' to read lines from a `StreamReader`, and a suggestion for you to try and see if it works any better. – fhcimolin Mar 07 '19 at 11:20