文件发送C#时出现问题.

编程入门 行业动态 更新时间:2024-10-09 13:23:48
本文介绍了文件发送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#时出现问题.

本文发布于:2023-10-31 10:33:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545822.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!