Know Transfer Rate
- From: "Bob" <a@xxxxx>
- Date: Wed, 15 Jun 2005 14:52:16 -0300
Hi.
I'm developed a simple Transfer File program just to test the NetworkStream
class. I want to know how can i get the transfer rate speed.
Does someone know how to do it? And... what's the size limit for the
transfer buffer? I set the buffer size to 1MB. It's ok? This is the code:
private void TransferFile(Socket clientConnection, string fileName)
{
NetworkStream ClientBridge;
FileStream FileToTransfer;
byte[] FileBuffer;
long FileSize;
long BytesTransfered;
int BytesReaded;
string PercentTransfered;
ListViewItem ClientItem;
try
{
FileBuffer = new byte[122880];
FileToTransfer = File.Open(SHARED_DIRECTORY +
fileName,FileMode.Open,FileAccess.Read);
FileSize = FileToTransfer.Length;
BytesTransfered = 0;
ClientItem =
GetClientItem(((IPEndPoint)clientConnection.RemoteEndPoint).Address.ToString
());
ClientBridge = new NetworkStream(clientConnection);
ClientItem.SubItems[1].Text = "Yes";
while(BytesTransfered < FileSize)
{
BytesReaded =
FileToTransfer.Read(FileBuffer,0,FileBuffer.Length);
ClientBridge.Write(FileBuffer,0,BytesReaded);
BytesTransfered = BytesTransfered + BytesReaded;
PercentTransfered = (((double)BytesTransfered * 100) / (double)
FileSize).ToString();
ClientItem.SubItems[2].Text = PercentTransfered + " %";
}
FileToTransfer.Flush();
ClientBridge.Flush();
FileToTransfer.Close();
ClientItem.SubItems[1].Text = "No";
}
catch(Exception ex)
{
throw ex;
}
}
Thanks Advanced.
.
- Prev by Date: User control and resizes
- Next by Date: stop window from resizing
- Previous by thread: User control and resizes
- Next by thread: stop window from resizing
- Index(es):