Search code examples
socketsnetworkingtcpudpdecentralized-applications

Is it possible to establish a connection between 2 computers without they knowing the IP of the other computer beforehand? If so, how?


I suppose this is a little bit of a decentralized computing question. If you want to write a software with no kind of authoritarian server that the clients already have some kind of address to, is it possible to make 2 clients/computers find eachother on the internet and have them send TCP or UDP packages between them?

If so, how? And how does softwares like Bitcoin solve this problem?

If anyone were to provide any code examples, python or C++ would be my preferred languages


Solution

  • It generally isn't possible. Decentralized systems solve the problem by finding each other's IP addresses from somewhere. Usually there's an authoritative server that the clients know the address of. Perhaps the only alternative is by by asking your friend and typing it into the software. Some viruses simply guessed random addresses, but that doesn't work all that well.

    Most decentralized systems make it so each node shares the IP addresses it knows with the nodes it's connected to, so that IP addresses can spread throughout the network. If your system does this, then it's not really that bad to have a server which shares some "getting started" IP addresses, as the client can learn the rest of them from the network. The risk is that the server could go bad and put clients onto the wrong network not connected to the main network.