tags:

views:

476

answers:

4

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.

A: 

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.

Eric J.
Thanks, but that is for c++, im looking for c#
Crazyd22
The approach should be useful regardless of language. However, I'm going to upvode nobugz. I wasn't aware of the PeerToPeer addition to .Net 3.5.
Eric J.
+4  A: 

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

Hans Passant
Do you have any links to sample code? The only actual code I find is a 2007 sample of resolving peer names, and the MSDN documentation seems to be a bit too much about the details of the classes and not how it all comes together. Thanks!
BarrettJ
Resolving names is what it is all about, the rest is easy. The official technology sample is here: http://msdn.microsoft.com/en-us/library/bb906998.aspx
Hans Passant
+2  A: 

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#.

romkyns
Ah okay thanks.
Crazyd22
A: 

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.

tjmoore