Hello. Can I see the network connection status? When sending a reply message ( listenerContext.Response.Close() ) an error pops up

Exception message "Attempt to perform an operation for a non-existent network connection"

  • use try/catch , throw error and tell you that there is no connection. - Bulson
  • with a large number of requests, the server hangs until it causes all exceptions (I would like to bypass them and not to cause and process them - Leonid
  • @Bulson is there a possibility not to cause an error? - Leonid

1 answer 1

Can I see the network connection status?

No, you cannot track the moment when the client stopped responding. The way to do this is to try to send something to the client and catch the exception. Therefore - try/catch

Is it possible not to cause errors?

As the documentation says, the flag IgnoreWriteExceptions is responsible for this opportunity IgnoreWriteExceptions

 HttpListener.IgnoreWriteExceptions = true; 
  • Thank! But tell me, in terms of the correctness of the code, will this be a good solution? Or is it better to process them? - Leonid
  • @Leonid common sense tells us that it’s better to somehow reflex into a catch block and close the connection correctly (see Dispose () / Abort ()) - Artyom Okonechnikov
  • Yes. That's exactly what I did. But with 10,000 requests the server hung until it threw all 10k exceptions, which is very slow for all the work. - Leonid