O
ohmmega
hello out there,
I use a thread data from a linuxserver. i ask for data, i read the
data (fix in size) - so far so good. this works great for the first 61
datapackages, then my thread abruptly freezes, because of the read
method. i can't locate the real reason. if I reconnect the tcpClient
after each package it works fine, but after several minutes the linux
programm quits (not my fault, not my code, not to change). has anybody
any clues about reason why this happens?
i just want to make a robust code. i thought about another thread
which works as watchdog - dataloss is no problem in this case. is
there a approved design pattern (snipplets) for this task?
thanks
rené
<code>
public byte[] getPackage(int PackageSize)
{
int SumBytes = 0;
byte[] PackageData= new byte[PackageSize];
NetworkStream myStream = getStream(...); //nonrelevant
while ( true )
{
if (myStream.DataAvailable)
{
SumBytes += myStream.Read(PackageData, SumBytes, PackageSize-
SumBytes);
if (SumBytes >= PackageSize)
{
break;
}
}
}
return PackageData;
}
</code>
I use a thread data from a linuxserver. i ask for data, i read the
data (fix in size) - so far so good. this works great for the first 61
datapackages, then my thread abruptly freezes, because of the read
method. i can't locate the real reason. if I reconnect the tcpClient
after each package it works fine, but after several minutes the linux
programm quits (not my fault, not my code, not to change). has anybody
any clues about reason why this happens?
i just want to make a robust code. i thought about another thread
which works as watchdog - dataloss is no problem in this case. is
there a approved design pattern (snipplets) for this task?
thanks
rené
<code>
public byte[] getPackage(int PackageSize)
{
int SumBytes = 0;
byte[] PackageData= new byte[PackageSize];
NetworkStream myStream = getStream(...); //nonrelevant
while ( true )
{
if (myStream.DataAvailable)
{
SumBytes += myStream.Read(PackageData, SumBytes, PackageSize-
SumBytes);
if (SumBytes >= PackageSize)
{
break;
}
}
}
return PackageData;
}
</code>