Click here to Skip to main content
15,850,685 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have made a simple Server/Client file transfer,
The Uploader has a 1MB/s upload bandwidth and downloader 12MB/s download bandwith.

Yet the max transfer speed is around 200kB/s, so a 5th of it's potential.
Is there anything that can be done to increase it's performance?

//File path in string file
FileInfo fi = new FileInfo(file);

int len = 0;
int rdby = 0;

FileStream fin = new FileStream(file, FileMode.Open, FileAccess.Read);
NetworkStream nfs = new NetworkStream(p);

//Send Header
byte[] tmp = new byte[9];
//File length
BitConverter.GetBytes(fi.Length).CopyTo(tmp, 1);
//Command byte
tmp[0] = (byte)Cmd.download;
nfs.Write(tmp, 0, tmp.Length);

//Send File, pSize = 1024
tmp = new byte[pSize];
while (rdby < fi.Length && nfs.CanWrite)
{
    len = fin.Read(tmp, 0, tmp.Length);
    nfs.Write(tmp, 0, len);
    rdby = rdby + len;
}
fin.Close();



Thanks for reading.
Posted
Comments
Sergey Alexandrovich Kryukov 19-Dec-11 15:11pm    
How do you know that 1M/s and 12M/s represent real speed, not just claimed? Did you time it by yourself? Did you time in using the same hosts?
--SA
Scalee 19-Dec-11 17:05pm    
I simply ran speed tests on the machines.

1 solution

I can see only two possibilities right now: 1) nfs.CanWrite is excessive (but hardly could affect your throughput much), 2) your buffer size is not optimal.

However, you cannot use arbitrary-size buffer in your code and improve performance. You should also check the maximum buffer size configured in your system. See http://msdn.microsoft.com/en-us/library/ms819736.aspx[^].

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900