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

Network stream error "Unable to read data from the transport connection."

P: n/a
Hello,

I'm trying to make a simple socket application, something like a chat
application, but when I run it, it shows the following error when the client
connects to the server: "Unable to read data from the transport
connection.". I'm posting the code, so if somebody can help I'll be very
grateful.

private void DoListen()
{
try
{
Server.Start();
Client = Server.AcceptTcpClient();
state = SocketState.Connected;
stream = Client.GetStream();
stream.BeginRead(dataBytes,0,dataBytes.Length, new
AsyncCallback(ReadStream),null);
}
catch
{
state = SocketState.Closed;
}
}

private void ReadStream (IAsyncResult args)
{
if (state == SocketState.Connected)
{
int I;
I = stream.EndRead(args); // The error happens here!!!
if (I > 0)
{
data = Encoding.ASCII.GetString(dataBytes);
stream.BeginRead(dataBytes,0,dataBytes.Length, new
AsyncCallback(ReadStream),null);
}
}
}

Thanks
Nov 15 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.