-4

I need to develop a file sharing apps over the internet by p2p. I have very rough idea for developing p2p based apps.

Suppose I have one server which has a static IP which is running at specific port like 5001. Now client connects to server and sends its own public IP.

Questions 1

With the help of C# how client can connect to server and send its own public IP? Guide me which class I need to use?

When server will get IP from client it will store. So when two clients connect then server has IP info of two different PCs. PC1 will request server to get the IP of PC2 and same way PC2 will request to get ip of PC1. So now PC1 & PC2 both have the IP of each other.

Questions 2

Now question is how PC1 can connect to PC2 which code i need to write to connect?

Questions 3

Now question is if PC1 can connect to PC2 then how PC1 can send file to PC2 ?

Please tell me which class I need to use in order to develop this type of P2P-based file sharing apps.

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
Thomas
  • 33,544
  • 126
  • 357
  • 626
  • possible duplicate of [How to implement P2P in C#?](http://stackoverflow.com/questions/1146637/how-to-implement-p2p-in-c) – Renatas M. Apr 20 '12 at 08:22
  • 1
    Have you tried doing anything yourself yet? What happened? Read anything about networking programming in c#? – maksimov Apr 20 '12 at 08:23
  • Whenever you ask a question, it is worth asking yourself: "what have I already tried?". If you then do some research and some _thorough_ web-searching before asking, then you'll not attract so many down-votes on your questions generally. – halfer Apr 20 '12 at 09:14
  • @Thomas - it'd be great to see you answer some questions too! You've asked 396 questions and answered 4 - can you try evening that up a little bit? `:-)`. – halfer Apr 20 '12 at 09:15

1 Answers1

0

When it comes to peer2peer, you always need at least one PC who has port forwarding enabled. This means, that if you have a listener/server at pc1 and a client at pc2, you would need a port forwarding on pc1.

This is called HighID/LowID in general and is a symptom of the NAT firewall implemented in almost every router. Without at least one port forwarding, there is no way two PCs can connect. This is because the router wouldn't know which local IP to map to an incoming TCP packet unless there is a forwarding.

As for what classes you can use: Take a look at System.Net.TcpClient and System.Net.TcpListener

bytecode77
  • 14,163
  • 30
  • 110
  • 141
  • can u plzz describe what is forwarding. developer need to write any code for forwarding? – Thomas Apr 20 '12 at 10:10
  • can u advise how to send client ip to server. with the help c# how can i send IP address to server. if apps on pc1 and apps on pc2 can send its own IP to server then apps on pc2 can communicate to apps on pc1 by the ip....need help which ip need to acquire and send by c#. please guide a bit with c# code as a result i can do some research and could develop the apps. thanks – Thomas Apr 20 '12 at 10:14
  • Port forwarding is a task done by the user of your application. This cannot be done by the application itself. Also the Client doesn't Send the IP to the server. It connects to a specific IP:Port (server). Read this article so you get a basic understanding of TCP http://www.codeproject.com/Articles/2418/Making-Socket-Based-Application-Using-TcpListener – bytecode77 Apr 20 '12 at 13:40