Python with socket communication between computers

Asked

Viewed 404 times

-2

Someone knows how to connect multiple computers with socket in Python, I’m creating a small test blockchain and I want to distribute the files among all the machines connected through the socket, I want to create a P2P, I want to know the logic to create a connection so that all of you communicate with everyone, synchronized, a force someone, I do not find this kind of information anywhere.

1 answer

1

There’s a reason why they invented HTTP over communication pr sockets, and then XMLRPC and JSONRPC over HTTP - sckets provide low-level communication - you have to worry about a lot of details, starting to accept communication and continue to do so in another async thread/process/task, so as not to block the server.

The best thing you do is to use a higher-level protocol than sockets, and then you can worry about your specific problem without re-inventing the wheel - I believe the Flask framework, possibly with an extension to facilitate Rest Apis for server-side communications and requests for the client part, for the communication part between us of your project.

A detailed explanation of how to do p2p communication via sockets in the correct way would be at least equivalent to a book chapter, and without any code of yours to look at, it is certainly outside the scope of this site.

(Remembering that for a blockchain project the part of networks can be the simplest - I have a project just without the network part, which is on github - if you are interested feel free to pick up things from there or build from it - https://github.com/jsbueno/pythonchain )

  • Thanks for the explanation, so the problem of my project and the use of the socket that is low level, I would have to use a websocket perhaps something higher level.

  • this - a common REST API with flask may be enough - a blockchain does not depend much on _how communication is done between nodes, but rather that the data is consistent between nodes after they have been transmitted - the bitcoin network itself has multiple network protocols, and depends on the configuration of each full Node as is access to other nodes. The answer contains further information: https://bitcoin.stackexchange.com/questions/79167/why-doesn-t-bitcoin-use-udp-to-do-blockpropagation

Browser other questions tagged

You are not signed in. Login or sign up in order to post.