Title: How do bitcoin nodes/miners use the same ports? Post by: NotElon on August 06, 2021, 04:09:06 AM Hello bitcointalk forum,
Quick question, as im trying to build a p2p decentralized network (just a chatroom network), i came across an issue: When Nodes communicate with each other, they use the same ports, nodes in this network act as a client and a server (They connect to another node and listen to other connections). The issue that I came across is that, 1 port can only be used to connect and since this port is used, i cant listen to other connections in this port. How do bitcoin nodes/miners communicate with each other using the same port? Any ideas on how to fix this? Title: Re: How do bitcoin nodes/miners use the same ports? Post by: achow101 on August 06, 2021, 04:29:40 AM It's just standard network software code. There's nothing special about Bitcoin or P2P software in this regard. It just combines client side software with server side software. Of course it requires having multiple threads/processes, but you should already be doing that for server side software anyways.
As with any client software, outgoing connections are made with random ports assigned by the operating system. Using standard system calls, a TCP connection will be opened by the OS using whatever port the OS decides. It works in the same way any software would to make connections to a server. As with any server software, incoming connections are handled using standard system calls (such as accept, poll, select, etc.) and then passed off to other threads for processing. It works in the same way that any server software does to accept incoming connections. Title: Re: How do bitcoin nodes/miners use the same ports? Post by: NotATether on August 06, 2021, 06:59:43 AM This shouldn't be an issue if you are running client and server on different machines. If you want to test something on the same machine, maybe you can configure one of your nodes to listen on one interface like an address on your 192.168 private subnet, and another to listen on localhost on another address in the subnet
The trick is to not bind to 0.0.0.0 (represents all of the interfaces). Title: Re: How do bitcoin nodes/miners use the same ports? Post by: odolvlobo on August 06, 2021, 08:05:56 AM How do bitcoin nodes/miners communicate with each other using the same port? Any ideas on how to fix this? The port is only used to listen for connection requests. |