can TcpClient :: GetStream() be used in separate threads for the same TcpClient ?
-
my server implements a reading thread that blocks until data is received. what I'd like to do is have a designated thread that only writes as data becomes available (an event would be created that contains the TcpClient in the event argument). Therefore the question: is it possible to use TcpClient.GetStream() twice for the same TcpClient ?
-
my server implements a reading thread that blocks until data is received. what I'd like to do is have a designated thread that only writes as data becomes available (an event would be created that contains the TcpClient in the event argument). Therefore the question: is it possible to use TcpClient.GetStream() twice for the same TcpClient ?
It's not possible. 'tcpclient.getstream() ' can get all btye[] by server socket sending.
April Comm100 - Leading Live Chat Software Provider
-
my server implements a reading thread that blocks until data is received. what I'd like to do is have a designated thread that only writes as data becomes available (an event would be created that contains the TcpClient in the event argument). Therefore the question: is it possible to use TcpClient.GetStream() twice for the same TcpClient ?
Yes, it's possible. You can't read or write by two threads, but having a thread that only reads and a thread that only writes is perfectly possible. I always do this but, in fact, I call GetStream only once, and pass the returned stream as the parameter to the threads, but I really think this don't change anything. Also, be carefull not to close the stream before you finished, as closing the stream will also close the tcp/ip connection.
-
Yes, it's possible. You can't read or write by two threads, but having a thread that only reads and a thread that only writes is perfectly possible. I always do this but, in fact, I call GetStream only once, and pass the returned stream as the parameter to the threads, but I really think this don't change anything. Also, be carefull not to close the stream before you finished, as closing the stream will also close the tcp/ip connection.
passing the TcpClient object around and calling GetStream() once in the read thread and once in the write thread worked just fine. Since I found this out I have updated my code to use a secure socket and now I'm passing around a NegotiateStream object (but no need to call GetStream) :)