469,313 Members | 2,536 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,313 developers. It's quick & easy.

Error when trying to use StreamReader to read from a NetworkStream

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
May 13 '06 #1
0 1118

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Astronomically Confused | last post: by
2 posts views Thread by Keith Kingsley | last post: by
1 post views Thread by Rob T | last post: by
reply views Thread by Brent | last post: by
6 posts views Thread by kikapu | last post: by
reply views Thread by Buddy Home | last post: by
reply views Thread by id10t error | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.