How come bittorrent clients manage to communicate to servers and other peers even if the user has not configured port forwarding on their routers?

Of course the speed will be reduced compared to when port forwarding is done, but still they manage to communicate? How???

Are there any inbound ports which are always open?

link|improve this question
I wonder why and who down voted this question!!! Whats the reason??? Whats wrong with the question? And @voter, if you don't have a good answer, just don't down-vote just because you can. And, please clarify whats wrong with this question? – Microkernel Oct 19 '10 at 7:01
How does your browser connect to the internet? Same thing... – leppie Oct 19 '10 at 7:01
@leppie - Browser is out bound connection, I am asking about the inbound connections. Say, user-A is sharing a file on bittorrent, and user-B wants to get that file, how does User-B's bittorrent manages to connect to User-A's computer? (I understand that user-B gets User-A's address from tracker, but how does User-B then connect to User-A?) And thanks in advance :) – Microkernel Oct 19 '10 at 7:05
@Microkernel: StackOverflow is for programming questions - general questions about computers, software and networks belong elsewhere, e.g. superuser.com or serverfault.com – Paul R Oct 19 '10 at 7:10
@Paul R, Hmm, I understand your concern. But I was actually trying to write a custom software for myself to synchronize files between my computers. And hence was wondering how they manage to connect to a computer even if port forwarding is not enabled.... This question was bugging me for a long time. So, asked here, as many people who are familiar with internals of Bittorrent are here. And I swear I am a Programmer ;) – Microkernel Oct 19 '10 at 7:15
show 1 more comment
feedback

migrated from stackoverflow.com Oct 21 '10 at 1:13

This question came from our site for professional and enthusiast programmers.

2 Answers

Inbound connections are accomplished by a third peer.

Say peer A wants to connect to peer F which is behind a firewall. Then peer A instructs peer B which is already connected to F that it wants to connect to F. F then gets the message and connects instead to A. I do not know the interna of the BT protocol, but B could be e.g. the tracker as it is well-known to both peers. For this scenario to work, A must accept incoming connections. AFAIK in Gnutella, F's ultrapeer played the role of B. This scenario generally works for TCP.

For UDP connections, check also UDP hole punching.

link|improve this answer
Thanks Damg... Yeah what you said really makes sense, but I am still struggling to understand the part where F connects to A... How F manages to connect to A from outside if A doesn't have port forwarding... And thanks for the answer :) – Microkernel Oct 19 '10 at 7:51
It is impossible to connect two firewalled nodes in case of TCP connections as both firewalls will not let incoming connections through to the desired node. There is UPnP which allows you to instruct the firewall to open/forward a port. Some applications do utilize the protocol successfully. If both hosts are firewalled and there is no possibility to instruct them to open the ports, you have two possibilities: non-firewalled third node to which both firewalled ones will connect and the third one will proxy the traffic or a change to UDP with hole punching which works in a lot of cases. – Damg Oct 19 '10 at 8:31
to connect A to F: let's say A wants to download a file from F, but F is firewalled. But A has the possibility to find out that F is already connected to B (a central directory or something similar). Then A looks up B and sends to it "hello, I am A (1.2.3.4:2888) and I want to communicate with F". B already has a connection to F and sends to it: "hello, here is 1.2.3.4:2888 and it wants to communicate with you". Then F connects to 1.2.3.4:2888 and tells: "hello, I am F, how can I serve you?". This process is called "pushing". – Damg Oct 19 '10 at 8:38
feedback

If a client has no port open (in the language of most small residental routers), that only blocks incoming connections.

A machine behind that router can still initiate connections with others. Once it does, the router remembers that and allows two-way communication. NAT, the function that lets you have more than one machine share a single public IP, has to do this to work.

So communication is possible with no open ports on your router, it's just your computer has to initiate it; an external machine cannot initiate connection with any computer behind that router unless you open a port, and connect a port to a specific IP behind your router.

I'm not too keen on the low-level details of the bittorrent protocol, but I think it or some revision thereof allows machines to receive data by initiating connections with others somehow, rather than just listening on an open port and waiting for an external machine to start a connection.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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