Take the 2-minute tour ×
Bitcoin Stack Exchange is a question and answer site for Bitcoin crypto-currency enthusiasts. It's 100% free, no registration required.

I'm trying to understand how exactly does the Bitcoin client communicate initially with another client, as I'm making my own client and learning new things about TCP protocol. As I understand, the Bitcoin client uses the standard port (8333) as a server port that is listening to other clients' communication, and the client opens up new ports as it is trying to communicate with other clients. As I'm not sure if I understand the communication correctly, I made this chart:

My question is: is this diagram and my assumptions correct, or did I make some mistake in understanding how the protocol works?

share|improve this question
2  
Since this is TCP, it's probably clearer to simply state that A opens a TCP connection to B's port 8333 and that this connection is used for subsequent communication between them. –  David Schwartz Nov 2 '11 at 22:57
add comment

1 Answer

up vote 1 down vote accepted

You're pretty close, with the deviations being I think primarily in terminology.

Client A listens for connections on port 8333. Listening is a server activity.

Client A chooses an ephemeral port and opens a connection to the address of Client B on port 8333, on which Client B is listening. At the TCP level, there is a three-way handshake to establish the connection. Imagine this connection as a bi-directional pipe to and from which both clients can read and write.

Once established, Client A sends Version and Client B receives it. Client B sends Version and Client A receives it. Client A sends Verack and I think Client B also sends Verack, which is an acknowledgement of the version compatibility or receipt.

This is my understanding.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.