文件发送C#时出现问题. [英] Problem in File Sending C#.

查看:82
本文介绍了文件发送C#时出现问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!我在C#网络编程中遇到问题,我正在使用UDP协议从服务器将文件发送到同一台计算机上的客户端.应用程序发送任何类型的文件.我根据文件的大小确定了缓冲区的大小,但是当我从服务器发送了超过126MB的文件,它已成功发送,但是在客户端上接收到的文件不超过126MB.这可能是问题所在吗?
请帮我.谢谢您的时间.

Hello everyone!I have a problem in C# network programming i am sending a file from server to client on same machine using UDP protocol.The application sends any type of file.I have made buffer size according to size of file but when i send file more than 126MB from server it is sent successfully but it is not received more than 126MB on client.What could be the problem?
Plz help me.Thanks every one for your time.

推荐答案

客户端缓冲区很小,我想如果您使用TCP,如果您不愿使用它会更好. "不要使用UDP,我建议您通过TCP将文件哈希发送给客户端,然后通过UDP发送文件,最后通过将您的哈希与接收到的哈希进行比较(如果它们不相等)来检查文件的正确性,再次发送文件

这将帮助您获取文件哈希

the client buffer is small, and i think if you use TCP it will be better, if you sill wan''t to use UDP i recommend you to send the file hash to the client by TCP, and send the file by UDP finally check the file correctness by comparing your hash with the received hash if they are not equal send the file again

this will help you to get the file hash

public String GetMD5Hash(String path)
{
    FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
    var hashValue = new MD5CryptoServiceProvider().ComputeHash(file);
    file.Close();
    return BitConverter.ToString(hashValue).Replace("-", "");
}

public String GetMD5Hash(byte[] source)
{
    var hash = new MD5CryptoServiceProvider().ComputeHash(source);
    return BitConverter.ToString(hash).Replace("-", "");
}


这篇关于文件发送C#时出现问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆