使用 UDP 协议在 C Sharp 中将文件从一台计算机发送到另一台计算机
我想使用 UDP 协议将文件从一台计算机发送到另一台计算机。我该如何执行此操作?
我想要一个样本来发送文件...
I Want Send A File From A Computer To Other Computer With UDP protocol.How Can I do this?
I Want A Sample To Send File...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用 UdpClient。
UDP 不能保证传送 - 如果您必须分解文件,这尤其成问题。请参阅此处的讨论 - 如何使用 C# UdpClient 发送大数据?< /a>
如果这是点对点的(如问题所示),则使用 传输文件。
You can use UdpClient.
Delivery is not guaranteed with UDP - if you have to break the file up, this is especially problematic. See here for a discussion - How to send large data using C# UdpClient?
If this is point-to-point (as the question suggests), it would be simple to write some native code to do this using TransmitFile.
使用 UdpClient 类。
Use the UdpClient Class.
UDP 没有固有的文件知识(它在协议栈中的位置要低得多),因此可能值得研究已建立的 基于UDP的文件传输协议。其中一些可能具有 .NET 实现。
否则,您将自己做很多工作(例如,确保文件被分成几部分,确保所有数据包都被接收并且它们以正确的顺序接收,等等)
UDP has no inherent knowledge of files (it is much lower in the protocol stack), so it might be worth investigating one of the established UDP-based file transfer protocols. Some of them might have .NET implementations.
Otherwise, you are going to be doing a lot of work on your own (e.g. ensuring that the file is broken up into pieces, making sure that all packets are received AND that they are received in the correct order, etc.)
下面的链接显示了如何使用 C# 发送和接收 UDP 数据包的各种示例
http:// /www.java2s.com/Code/CSharp/Network/UdpClientMultiReceive.htm
The link below shows various examples of how to send and receive UDP packets with C#
http://www.java2s.com/Code/CSharp/Network/UdpClientMultiReceive.htm