Peer to Peer file transfer c#

2019-03-26 13:00发布

问题:

Hey, I have been looking on google and I cannot seem to find anything about peer to peer transfer.

Basically, I want to be able to send a file from my computer to someone else's computer. Does anyone know of any guides that can help me with this?

Thanks.

回答1:

If you really just want to "send a file from my computer to someone else's computer" using C# then you may not be looking for true p2p. You can just use raw TCP. For this you need the remote computer to listen for a connection, your computer to open a connection to the remote computer, and start sending data.

There's a very basic example on how to do something like that here.

If you are actually looking for true P2P then you're best off using an existing P2P network (otherwise there will be nobody but you and your other computer on it). There are a few C# BitTorrent libraries around - for example BitSharp, TorrentNet. There is a whole question about BitTorrent libraries written in pure C#.



回答2:

Google "System.Net.PeerToPeer", a namespace available in the .NET 3.5 framework. You'll have no trouble finding docs and sample code.



回答3:

If the destination computer is able to expose a URI to publish to then you can simply use

WebClient.UploadFile(Uri address, string filename)

It very simply just takes a URI as address (http, ftp, even the file protocol to transfer to a folder share).

But that does require setting up something server side to publish to, but it would be platform independent on the server (e.g. any old FTP server, or a web page or service that accepts a file by POST method). Security may be an issue you need to consider however.

That's using a push model. WebClient can also be used from the other side to download. It also supports transfer of data streams, strings, etc.



回答4:

Have a look at this project on Code Project.

It provides for P2P chat and file transfer and could be either an inspiration or a solution.



标签: c# transfer peer