This is not ideal, but if you check socket.Available , it will throw a SocketException . However, you still need to check the reason.
Also not perfect, because it's a bit awkward, you need to call Poll() (using SelectRead ). If it returns true , either the data to read, or the connection is closed. If there is no data to read, then your answer.
source share