V
V
Vladislav Shcherbakov2015-02-06 17:49:55
C++ / C#
Vladislav Shcherbakov, 2015-02-06 17:49:55

How to implement peer-to-peer technology?

I am writing a program that transfers files between computers (local) using peer-to-peer technology.
Faced the following difficulties:
1) There is a lot of chewed information on socket programming for Linux, but I would like it under Windows. MSDN smoked, but it would be desirable more detailed.
2) How to search for computers running the program? It is advisable to search on all interfaces. That is how to find the list of local computers? Or you may not know their list, but simply send some kind of broadcast request to a specific address and wait for a response? (Now I'm content with parsing the output of the standard "arp" utility with the "-a" switch, but I don't understand what request to send to these IPs and how to wait for it on those computers)
ZY: Such a task was given at the hackathon. Our team's pupils widened outside the city: D We achieved some results in a day, but in a "non-Jedi" way. Compiled pieces of code found in Google. And it turned out not p2p, but a client-server application. I liked the task, I decided to understand the topic a little more than completely.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
tsarevfs, 2015-02-07
@tsarevfs

Programming on pure sockets is quite laborious. In addition to the fact that you have to work at a fairly low level, to ensure their non-blocking work (for example, when waiting for data from another client), you must use either streams or poll / select.
A good way out is to use a wrapper, for example from Qt. This way you get cross-platform code at a lower cost. It's also worth looking at higher-level options like ZeroMQ (I don't know about p2p, but for communication between 2 clients it might make life easier).
In the simplest case, to notify of its presence, the client sends broadcast udp packets with information about itself. The main problem with this approach is that such packets will be killed by the nearest router (it is naive to believe that we will be allowed to send a packet to every Internet user). Therefore, this approach only works in a simple local network. Bittorent can store information decentralized, but for the initial connection, you need to know the address of at least one connected participant.
Once you know the address of another client, you can establish a direct connection with him. In fact, everything is not so simple here either. If it is behind NAT, and before the distribution of ip-v6 for most (?) Clients, this is how it is, then you will have to come up with something. On this topic, you can search for "p2p over NAT".

U
uvelichitel, 2015-02-06
@uvelichitel

The dumbest option: peers register on a service that serves exclusively for service discovery.

V
Vitaly Pukhov, 2015-02-13
@Neuroware

if we are talking about local p2p, then either a broadcast request or search for machines manually, for this you need to find out the subnets on all available interfaces and sort through all the "hello" requests to a specific port of your program, enumeration in any normal network will take no more than 5 seconds.
everything else depends on the language, at least you can build a mesh network there.
ps the idea is interesting, but the practical sense in it is not particularly visible.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question