End Google Ads 201810 - BS.net 01 --> Im trying to make an app, that i can download my mails from my account.

For the test i have 4 mails, total 200kb. When i download the mails, it takes 30 secs.. aprox.. A LOT! and i dont know how to improve the velocity.


Thanks!


The code that i use to download is this:

ns = networkstream from a TCP, buffer 8192.
private string getemailtest2(int indexservidor)
{
StringBuilder resp1 = new StringBuilder();
bool begin = true;

int compa = 8193;
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
while (true)
{
byte[] dataaleer = new byte[8192];
if (ns.DataAvailable || begin)
{
int a = ns.Read(dataaleer, 0, 8192);
}
resp1.Append(enc.GetString(dataaleer).Trim('\0'));
if (begin)
{
compa = Int32.Parse(resp1.ToString().Split(' ')[1]);
begin = false;
}
int leng = enc.GetBytes(resp1.ToString()).Length;
if (leng >= compa)
{
if (!ns.DataAvailable)
{
break;
}
}

}
return resp1.ToString();