展开全部
const int blockLength=512*1024;
public void SendFile(string filePath, NetworkStream stream) //发送文件
{
//传输内容
using (FileStream fs = File.Open(filePath, FileMode.Open))
{
int readLength = 0;
byte[] data = new byte[blockLength];
//发送大小e69da5e6ba9062616964757a686964616f31333339663938
byte[] length = new byte[8];
BitConverter.GetBytes(new FileInfo(filePath).Length).CopyTo(length, 0);
stream.Write(length, 0, 8);
//发送文件
while ((readLength = fs.Read(data, 0, blockLength)) > 0)
{
stream.Write(data, 0, readLength);
}
}
}
public bool ReceiveFile(string fileName, NetworkStream stream) //接收文件
{
try
{
long count = GetSize(stream);
if (count == 0)
{<