UncleRonin
Well-known member
I have an app which listens to a certain port indefinitely. It accepts requests from whatever clients or other applications and reads the data and dumps it. These clients and apps won't always be on Windows or whatever so there's none of the cool .NET stuff for serializing and all those good things.
What I'd like to know is what is the best way to determine when to stop reading from a stream/socket? At the moment I've set a receive timeout so that if all the data isn't read with 100ms between characters it'll throw a SocketException and I'll finalise everything else in a finally block. I have no idea what length the data will be.
To me this doesn't seem very good because I'm actually forcing and using an Exception to tell the state of the stream/socket.
Is there not a better way to do this? There are all the .Connected and .EndOfStream states but they don't cater for this, at least not as far as I can tell. I've tested with them and they're pretty crap to be honest.
Does anyone know of a better way to handle this situation? It's really quite a nuisance.
What I'd like to know is what is the best way to determine when to stop reading from a stream/socket? At the moment I've set a receive timeout so that if all the data isn't read with 100ms between characters it'll throw a SocketException and I'll finalise everything else in a finally block. I have no idea what length the data will be.
To me this doesn't seem very good because I'm actually forcing and using an Exception to tell the state of the stream/socket.
Is there not a better way to do this? There are all the .Connected and .EndOfStream states but they don't cater for this, at least not as far as I can tell. I've tested with them and they're pretty crap to be honest.
Does anyone know of a better way to handle this situation? It's really quite a nuisance.