Bitcoin Forum
September 20, 2024, 02:18:02 AM *
News: Latest Bitcoin Core release: 27.1 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How do bitcoin nodes/miners use the same ports?  (Read 92 times)
NotElon (OP)
Newbie
*
Offline Offline

Activity: 1
Merit: 0


View Profile
August 06, 2021, 04:09:06 AM
 #1

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?
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3500
Merit: 6833


Just writing some code


View Profile WWW
August 06, 2021, 04:29:40 AM
Merited by ABCbits (3), pooya87 (2), BitMaxz (1)
 #2

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.

NotATether
Legendary
*
Offline Offline

Activity: 1736
Merit: 7273


In memory of o_e_l_e_o


View Profile WWW
August 06, 2021, 06:59:43 AM
 #3

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).

odolvlobo
Legendary
*
Offline Offline

Activity: 4438
Merit: 3387



View Profile
August 06, 2021, 08:05:56 AM
 #4

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.

Join an anti-signature campaign: Click ignore on the members of signature campaigns.
PGP Fingerprint: 6B6BC26599EC24EF7E29A405EAF050539D0B2925 Signing address: 13GAVJo8YaAuenj6keiEykwxWUZ7jMoSLt
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!