我的项目是FTP,我需要一些帮助 1.我正在使用Huffman Code压缩文件,然后将其发送到询问文件的计算机。
来自霍夫曼代码的函数返回字节数组 我不明白如何发送字节。
我有这个功能:
private void UpLoad(string namefile)
{
try
{
FileInfo ftemp = new FileInfo(ClientForm.SharedFolderPath + "\\" + namefile); // file name
long total = ftemp.Length; // size of file in long
long rdby = 0;
int len = 0; // the numbers of bytes to read
byte[] buffed = new byte[1024];
//Open the file requested for download
FileStream fin = new FileStream(ClientForm.SharedFolderPath + "\\" + namefile, FileMode.Open, FileAccess.Read);
//One way of transfer over sockets is Using a NetworkStream
//It provides some useful ways to transfer data
NetworkStream nfs = client.GetStream();
//lock the Thread here
lock (this)
{
while (rdby < total && nfs.CanWrite)
{
//Read from the File (len contains the number of bytes read)
len = fin.Read(buffed, 0, buffed.Length);
//wait for downloader..
Thread.Sleep(1);
//Write the Bytes on the Socket
nfs.Write(buffed, 0, len);
//Increase the bytes Read counter
rdby = rdby + len;
}
//Display a Message Showing Sucessful File Transfer
fin.Close();
}
}
catch (Exception ed)
{
MessageBox.Show(ed.Message);
}
}
是的,有人能帮帮我吗?
最好的方法是什么?