By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,775 Members | 1,347 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,775 IT Pros & Developers. It's quick & easy.

Error when trying to use StreamReader to read from a NetworkStream

P: n/a

Hey,

Has anyone ever got a "Unable to read data from transport connected" message
after reading data from a streamreader composed of a networkstream.

For example:

Server

TcpListener tcpServer = new TcpListener(localAddr,port);

TcpClient tcpClient = new TcpClient()
tcpClient = tcpServer.AcceptTcpClient();

NetworkStream networkStream = tcpClient.GetStream();

StreamWriter stringWriter = new StringWriter(networStream);

string lstrData = "An XML string"; // this is really a xml string
stringWriter.WriteLine(lstrData);
stringWriter.Flush();

-----------------------------
Client
--------

TcpClient tcpClient = new TcpClient("localhost",port);

NetworkStream networkStream = tcpClient.GetStream();

StreamReader streamReader = new StreamReader(networkStream);
string strData = streamReader.ReadLine();

-----------------------------------------------

When debugging networkStream is readable and has dada available, but
streamReader.ReadLine() returns the above error message: "Unable to read
data from transport connected".

BTW, the Server is sending the data fine, it's just the client that's not
reading fromt he stream.

Does anyone have any ideas of what I might be doing wrong here?

Much thanks in advance,

--
Al

--
Al
May 13 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Al Wilkerson <ac***@comcast.net> wrote:
Has anyone ever got a "Unable to read data from transport connected" message
after reading data from a streamreader composed of a networkstream.


That sounds quite odd. Could you post a short but complete program
which demonstrates the problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

(The code you provided wouldn't compile - StringWriter isn't a
StreamWriter, for starters.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
May 13 '06 #2

P: n/a
Never mind I found out I had another StreamReader object hanging around. So
my problem is fixed.

Thanks,

Al
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Al Wilkerson <ac***@comcast.net> wrote:
Has anyone ever got a "Unable to read data from transport connected"
message
after reading data from a streamreader composed of a networkstream.


That sounds quite odd. Could you post a short but complete program
which demonstrates the problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

(The code you provided wouldn't compile - StringWriter isn't a
StreamWriter, for starters.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

May 15 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.