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...
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.
The TransmitFile function transmits file data over a connected socket handle. This function uses the operating system's cache manager to retrieve the file data, and provides high-performance file data transfer over sockets.
Use the UdpClient Class.
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.)
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
精彩评论