Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: redigaffi on August 08, 2018, 02:44:59 PM



Title: Nodes talking, sockets or over http
Post by: redigaffi on August 08, 2018, 02:44:59 PM
Hello, I have a question, I know that (at least in bitcoin) nodes talk to each other opening sockets to communicate if I'm not wrong. What I've seen so far this is like a standard for other cryptocurrencies. What If I would create a cryptocurrency, but communicating over HTTP protocol, for example using JSON post request. I know that this would be potentially slower due to an extra layer of the HTTP protocol.

But could it work?
Would it make sense?


Title: Re: Nodes talking, sockets or over http
Post by: bob123 on August 08, 2018, 02:56:29 PM
I know that (at least in bitcoin) nodes talk to each other opening sockets to communicate if I'm not wrong.

Each piece of software on a PC has to open a socket to communicate with a network.



What If I would create a cryptocurrency, but communicating over HTTP protocol, for example using JSON post request. I know that this would be potentially slower due to an extra layer of the HTTP protocol.

I don't see any pro argument for building a cryptocurrency on top of HTTP. You would just require everyone to additionally run a web server to be able to communicate with the network.
There is no necessity for something like this.



But could it work?

Well, theoretically you can do each communication over HTTP but this doesn't give you any advantage. Just disadvantages.



Would it make sense?

No, note at all. At least not in my eyes.

What exactly were you trying to do? Which problem of BTC are you trying to solve with this method?


Title: Re: Nodes talking, sockets or over http
Post by: redigaffi on August 08, 2018, 03:01:09 PM
Thanks for your answer.

Well the idea was to built a small webserver into the node so they don't need to have a web server running apart.

Actually, it's just curiosity, and im not building anything. I've started some months ago a CryptoCurrency written in node.JS and I was using HTTP protocol for sending/receiving info, but I'm thinking to switch to C++. Anyway, just doing this for fun and learn more.


Title: Re: Nodes talking, sockets or over http
Post by: Honour423 on August 09, 2018, 02:02:29 AM
If you are starting out with node.js then sockets.io is a good place to start.  It’s pretty easy to create listeners on any port you want. If you are just learning basics then creating a REST api over http is an ok place to learn but won’t support anything major.  When you need to start moving blocks across nodes that are in the multi megabyte size range then http will fall apart on you.  IP*Works has some great socket libraries if you want to build something major, but it’s kind of expensive. 


Title: Re: Nodes talking, sockets or over http
Post by: redigaffi on August 10, 2018, 08:33:58 AM
Btw, how does nodes send the data? is there any format (in bitcoin?) for example, json or xml?


Title: Re: Nodes talking, sockets or over http
Post by: bob123 on August 10, 2018, 01:31:48 PM
Btw, how does nodes send the data? is there any format (in bitcoin?) for example, json or xml?


The message structure is:
  • 4 byte which define mainnet/testnet
  • 12 byte command
  • 4 byte length
  • 4 byte checksum
  • X byte payload

You can read more about the structure / possible values in the protocol documentation (https://en.bitcoin.it/wiki/Protocol_documentation#Common_structures (https://en.bitcoin.it/wiki/Protocol_documentation#Common_structures)).