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 |