I'm making a TCP server, which handles async writing and reading. When a client is connected it will start listening to messages with "readAsync".
public async void ReadClientDataAsync()
{
int result = 1;
while (result != 0)
{
if (networkStream.DataAvailable)
{
byte[] data = new byte[4096];
result = await networkStream.ReadAsync(data, 0, data.Length);
Debug.WriteLine(System.Text.Encoding.ASCII.GetString(data));
}
}
networkStream.Dispose();
tcpClient.Dispose();
Console.WriteLine("DONE");
}
This is not working. It is so strange that only works when I "step into" debug. I'm not sure what's going on.
I'm using netcat to test this out, no need to write a client.