private void HandleClientCommSS(object client)
{
// Getting the dataStream
TcpClient tcpClient = (TcpClient)client;
NetworkStream clientStream = tcpClient.GetStream();
// Custom variables
byte[] incoming_raw_data = new byte[4096];
int bytesRead;
int oldPos = 0;
long currentPos = 0;
while (true)
{
bytesRead = 0;
try
{
bytesRead = clientStream.Read(incoming_raw_data, 0, 4096);
}
catch
{
break;
}
if (bytesRead == 0)
{
break;
}
// -- We got a valid raw data - proceeding to write...
if(toWrite==null)
toWrite = new FileStream(locationToSave, FileMode.Create, FileAccess.Write);
toWrite.Write(incoming_raw_data, 0, bytesRead);
currentPos += bytesRead;
if ((currentPos / 1000) - oldPos > 10)
{
owner.ReportInSS = (currentPos / 1000).ToString() + " KB transferred";
oldPos = (int)(currentPos / 1000);
}
}
clientStream.Close();
clientStream.Dispose();
tcpClient.Close();
if (toWrite != null)
{
toWrite.Close();
toWrite.Dispose();
}
isListening = false;
listener.Stop();
owner.ReportInSS = "complete<%SEP%>" + locationToSave;
}