R
Ryan Liu
Hi, I have some basic question about NetworkStream, can someone explain to
me? Thanks a lot in advance!
TcpClient has a GetStream() method return a NetworkStream for read and
write.
I remember there are 2 streams in Java, one for read, one for write.
If I just use synchronous Read() and Write() method:
If I have two threads, one reads, and another writes to the stream, and I
don't use any lock mechanism, will read/write operations overlap and
conflict each other, and raise exception? Or it internally has a way to
gurantee the safety?
And if I have two write threads, and there is no lock mechanism, will two
write operations interfere each other, and the receiver get mixed data?
If I use BeginRead(), BeginWrite() asynchronously in multiple threads, will
that solve the problems above(if any)? And is it safe not to use my own
lock mechanism in asynchronous mode?
Thanks again!
Ryan Liu
Thanks a lot!
me? Thanks a lot in advance!
TcpClient has a GetStream() method return a NetworkStream for read and
write.
I remember there are 2 streams in Java, one for read, one for write.
If I just use synchronous Read() and Write() method:
If I have two threads, one reads, and another writes to the stream, and I
don't use any lock mechanism, will read/write operations overlap and
conflict each other, and raise exception? Or it internally has a way to
gurantee the safety?
And if I have two write threads, and there is no lock mechanism, will two
write operations interfere each other, and the receiver get mixed data?
If I use BeginRead(), BeginWrite() asynchronously in multiple threads, will
that solve the problems above(if any)? And is it safe not to use my own
lock mechanism in asynchronous mode?
Thanks again!
Ryan Liu
Thanks a lot!