How does BitTorrent work

Hi all, I hope you’re well.

For the longest time I’ve been wondering why is it that when I’m trying to run my own web server on my home PC and open it up to the public I have to go through a whole process ie. opening up ports, setting up rules on the router, setting up DDNS, but torrent clients work effortlessly without any problems. They also accept incoming traffic so what makes these two things different?

Thanks :slight_smile:

1 Like

A lot of clients use UPnP so if the router supports it, and when enabled it, will do the port forwarding for you. It’s also based on the BitTorrent P2P protocol and doesn’t work like a web server.

1 Like

Thanks for replying lasjorg!

UPnP still runs on top of HTTP from what I gathered so why don’t Apache, NGINX or Node use it as well? Is it for security purposes or am I missing something here? And I understand the P2P nature of BitTorrent which makes me even more surprised it’s so easy to allow other computers to connect to mine but setting up a web server is such a pain.

There’s a few reason a web server is harder to set up than a BitTorrent client:

  • On Unix systems, which is most web servers, it has to listen on “privileged” ports, namely 80 and 443, which by default only the root (admin) user can do.

  • The machine has to be reachable on the public internet. UPnP can open a port to make that so for BT, but BT doesn’t require it.

  • You need a domain name for people to reach your server on the public internet. Local HTTP servers like your router can get away with just an IP address, but a TLS cert demands a domain name. That TLS cert also has to be issued by a third party, though that’s almost automatic these days with letsencrypt. Almost.

Setting up a simple web server is otherwise pretty trivial: there are dozens of apps where it’s literally a one-liner. Such as http-server for nodejs.

Also, UPnP is definitely not based on BitTorrent. For one, it predates BT. BT clients just happen to use it (and sometimes NAT-PMP, a different protocol altogether). Apache and nginx serve HTTP: they’re a layer below UPnP, not above. Node is just a JavaScript interpreter outside of a browser, it’s not intrinsically an HTTP server, though it’s often used for that.

UPnP isn’t suited for use anywhere but a local network, since it has no concept of authentication. There were projects to extend UPnP and similar to the internet at large, but they all fizzled out. Which is fine by me, UPnP is a gnarly and complicated protocol anyway.

There are some interesting projects for a P2P web, such as IPFS though odds are they’re not going to significantly displace the current web for the foreseeable future. FreeNet was an earlier attempt at this sort of thing, but it never worked that well, and quickly turned into a Dark Web of kiddie porn.

1 Like

Just to be clear. I wasn’t saying UPnP was based on BitTorrent. That was just a poorly constructed sentence on my part. The “its” was referring to BitTorrent, not UPnP (i.e. BitTorrent is based on the BitTorrent P2P protocol).

Gotcha :+1:


Thanks for the detailed ansewer Chuck.

I understand that ports below 1024 are priviliged and that installing a server is not a difficult task. What I don’t understand is why when I run an express (for example) server on port 3000, 5000, or whatever I can’t connect to it by entering my my public IP into the browser without setting up so many things, some on the router, while all other network applications just work. I have to set up port forwarding, DDNS etc.
I used BitTorrent as an example because it’s a P2P network meaning my computer must be accessible from the outside without any setup

Because setting up servers just isn’t commonly done by end-users on home PCs. There’s no reason a server setup couldn’t automatically open the port in the firewall, but the majority of people running servers don’t want that kind of behavior – the firewall exists for a reason. You can always permanently open those ports on your router, and you’d only ever have to do it once.

1 Like

I don’t think the firewall is the issue here. Let’s just say I set up an express server on port 3000. I opened the port in the firewall, or even disabled it completely. I enter my public IP with the port in the browser and… nothing. Can’t establish the connection. Meanwhile my BitTorrent does its thing just fine. Am I being stupid here or is some traffic just treated differently by the OS (Windows in this case) or the router?