Bitcoin client two-way communication



When client A opens a connection to client B, it opens its TCP connection to second client's port 8333. Is this connection solely used for A's queries and B's answers to A's query, or can B also query A using the same connection?

For example, A can ask B for list of known peers using this connection, but can B ask A for the same using the connection A established, or does B need to open a new connection to A's port 8333, exchange version messages, and only then send its queries?


Posted 2011-11-03T12:53:50.333

Reputation: 42 235



I changed wording of the quote a bit, so it would match your question.

When you connect to a client, you will receive responses on the port you just used to connect to that client. The Bitcoin network uses persistent TCP connections that remain active so long as both nodes continue running.

Bitcoin communication with non-standard ports

For the sake of discussion we can define Server as the side that waits or listens on port 8333 and Client as the side that initiates connection by sending network packet to "server_ip_address":"8333" , the network packet has address of the Client, so Server can send reply back to "client_ip_address":"any_port_reserved_for_client_on_client's_network" .

Bitcoin always reserves 8333 port on workstation to communicate with Bitcoin Network, but usually home router changes the port number in packet when it's on it's way out for the Network Address Translation mechanic (NAT). To overcome NAT and make Bitcoin Client act as Server and accept incoming connections, Port Forwarding or UPnP should be enabled.


Posted 2011-11-03T12:53:50.333

Reputation: 5 240

So you only receive responses to your queries, and you shouldn't expect other clients to send you their queries to port other than 8333? – ThePiachu – 2011-11-04T10:19:17.747

I edited my answer to clarify things. – Serith – 2011-11-04T11:50:46.757

I don't think you're answering the question that was asked. He's asking whether it matters who listens and who connects. It doesn't, as Gavin's answer says. Once a connection is made, both sides can send requests and responses through that connection. Also, Bitcoin doesn't always reserve port 8333; it's configurable by the user with the -port=<port> command line argument. – Chris Moore – 2012-02-26T19:27:51.660


Once the connection is established, the communication is completely symmetric-- either end can ask the other anything.


Posted 2011-11-03T12:53:50.333

Reputation: 3 282