Soldato
- Joined
- 12 Apr 2004
- Posts
- 11,788
- Location
- Somewhere
I have the following code, which simply reads data from a TCP connection with a server:
This all works perfectly, and returns 41 bytes of data, if I step through the line typed in bold (a break point must be placed on that line or before, then stepped trough). If I don't, client.Available remains at 41, and availableData at 0.
I'm stumped. Any ideas?
Code:
private byte[] GetTcpData()
{
if (m_IsQueryInProgress)
{
return m_CachedTcpData;
}
m_IsQueryInProgress = true;
try
{
TcpClient client = new TcpClient();
client.Connect(m_ServerAddress, m_TcpPort);
client.ReceiveTimeout = Properties.Settings.Default.TcpTimeout;
client.SendTimeout = Properties.Settings.Default.TcpTimeout;
[B]int availableData = client.Available;[/B]
using (Stream stream = client.GetStream())
{
BinaryReader reader = new BinaryReader(stream);
m_CachedTcpData = reader.ReadBytes(availableData);
}
return m_CachedTcpData;
}
finally
{
m_IsQueryInProgress = false;
}
}
This all works perfectly, and returns 41 bytes of data, if I step through the line typed in bold (a break point must be placed on that line or before, then stepped trough). If I don't, client.Available remains at 41, and availableData at 0.
I'm stumped. Any ideas?
