Also, if the connection exists and there is no data in the stream, readByte seems to wait until it can read a byte. So this makes it difficult to use exception handling to determine if the connection exists or not.
----- Pi wrote: -----
Peek returns -1 (when no data in stream) regardless of whether a connection is currently there or not. It appears that until a read operation is attempted the stream thinks everything is ok. Once I do the read operation the following exception is thrown "Run-time exception thrown : System.IO.IOException - Unable to read data from the transport connection". This is okay, but I would love to know a method that doesn't consume data from the stream.
Do you know of any other way to acheive this?
----- Adrian Forbes [ASP MVP] wrote: -----
I tried inheriting TcpClient to access the protected function Client
Connected but this returns true even when the connection has been lost.
I found that myself. If you want to look at the stream without "reading" it
you could try a Peek as that will return data from the stream but not
advance the stream position so you can always re-read the data using a get.