Peer to Peer file transfer c#

99封情书 提交于 2019-12-04 11:02: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.



来源:https://stackoverflow.com/questions/1821680/peer-to-peer-file-transfer-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!