[Mono-devel-list] BufferedStream BeginRead and write together

Jeroen Asselman jeroen at asselman.com
Tue Aug 17 17:12:24 EDT 2004


I have a question because I wonder if I using the correct methods to 
achive what I want.

I have a client/server program which maintains a tcp connection with 
another client/server. To test wether the connection is still alive a 
client can send a ping request. The other will respond with a pong.

To listen for incoming data I use the BeginRead method on the 
tcpstream. When using the NetworkStream everything seems to go 
I can send a ping on the other client and the BeginRead function will 
call the callback function and I can read the data after which I invoke 
the BeginRead method again.

However, it can happen that the network connection gets dropped. I use 
the BufferedStream to read as much data as possible. Because when the 
connection drops I might get an socketexception and not read yet all 
the data, even when the other client did send everything. With a 
bufferedstream at least this data is received so I can parse the 
connection drop reason.

However, a BufferedStream doesn't like it when I have a BeginRead and 
then start Writing data over the same stream (to do a ping).

Am I using the wrong approach? Or should I drop the bufferedStream 
class and implement my own sort of BufferedStream class which can do 
Reading and Writing at once?

- Jeroen

ps. I hope these kind of questions are valid here.

More information about the Mono-devel-list mailing list