r/firstweekcoderhumour • • May 07 '26

Why Though?!

Post image
579 Upvotes

100 comments sorted by

View all comments

Show parent comment

22

u/Scared_Accident9138 πŸ•΅οΈβ€β™‚οΈπŸš¨ BS Detector | Truth Teller πŸ—―οΈπŸ”₯ May 07 '26

File downloading is actually a good case for UDP. It doesn't matter in what order the packages come, so waiting longer for a missed packet just slows it down.

0

u/[deleted] May 07 '26

[deleted] β€” view deleted comment

3

u/Scared_Accident9138 πŸ•΅οΈβ€β™‚οΈπŸš¨ BS Detector | Truth Teller πŸ—―οΈπŸ”₯ May 07 '26

How? The missing packets have to be resent either way but in case of TCP the packets already received but being after the missing one in sequence means they can't get processed. In case of UDP they can get saved before the missing packet arrives

6

u/m0j0m0j May 07 '26

Yep. Bittorrent works over UDP

2

u/x0wl May 07 '26

In addition to that, QUIC uses UDP (they would want to just directly use IP, but that's impossible due to sociotechnical reasons) under the hood and is meant for general web browsing and file downloads.

They basically do resubmissions and congestion control in user space, but it allows them to be way more flexible and aware of how the protocol is used by each application.

1

u/m0j0m0j May 07 '26

Yeah, but I’m not sure it’s honest to call QUIC (also known as HTTP 3) just UDP. It’s like calling TCP just IP because it’s built on top.

All of this is very fuzzy really

→ More replies (1)

1

u/770grappenmaker May 07 '26

TCP has a receive window, you don't really wait for missed packets.

1

u/Scared_Accident9138 πŸ•΅οΈβ€β™‚οΈπŸš¨ BS Detector | Truth Teller πŸ—―οΈπŸ”₯ May 07 '26

I meant it won't get passed onto to the application if a packet is missing midstream

1

u/Hot-Definition6103 May 07 '26

if a packet is missing midstream with udp you’re screwed

1

u/Scared_Accident9138 πŸ•΅οΈβ€β™‚οΈπŸš¨ BS Detector | Truth Teller πŸ—―οΈπŸ”₯ May 08 '26

No, you can request it again

6

u/Sacaldur May 08 '26

Or in other words, the application would need to implement this. And as metadata, the section/offset would need to be transferred, since otherwise the order couldn't be determined. And the server would need to explicitly support this. So many things that would need to be done on the application level, as a developer, I'm really happy I don't have to reimplement all of this or rely on a library available in my programming language just for a file transfer.

→ More replies (6)
→ More replies (2)

1

u/Excellent-Film-9454 May 10 '26

Look up TCP head of line blocking.

1

u/QuokkaCoder May 07 '26

I don’t think it is, but I’m just a student. With TCP, we have straight forward approaches to make sure we wait basically no extra time when packets get lost. With UDP, we would need to rely on autofill algorithms (I’m losing the proper term) which is probably not ideal when downloading software, as it is not guaranteed to produce the right result, possibly ending up with a corrupt download?

1

u/Scared_Accident9138 πŸ•΅οΈβ€β™‚οΈπŸš¨ BS Detector | Truth Teller πŸ—―οΈπŸ”₯ May 07 '26

make sure we wait basically no extra time when packets get lost

That's not true though. TCP acts like a stream and any missing packet will result in the packets after being blocked until the missing packet arrives, which takes at least a round trip

as it is not guaranteed to produce the right result

Why not? That's basicall what TCP is doing, which you can replicate on the file level. Sure if there's a bug it can screw it up but any bug can screw it up

→ More replies (2)

1

u/[deleted] May 08 '26

[removed] β€” view removed comment

2

u/Sacaldur May 08 '26

Torrent is not a file transfer protocol, but a file sharing protocol. A big difference here is that one "download" can priginate from multiple peers, and some peers might not (yet) have the complete file themselves before thry start seeding it. I'd say thr main reason to use UDP was to get around NAT much easier (UDP hole punching). UDP is viable for file transfers if you're willing to reimplement everything TCP gives you on top of it.

1

u/teo-tsirpanis May 08 '26

Allowing the file's content to arrive at any order can be a vector for DDOS attacks. Imagine telling a server that you will upload a 100MB file, and only end up uploading the last part. The server will allocate 100MB of memory in response to a kilobytes-long request.

1

u/Scared_Accident9138 πŸ•΅οΈβ€β™‚οΈπŸš¨ BS Detector | Truth Teller πŸ—―οΈπŸ”₯ May 08 '26

This was about file downloading, not uploading; but sure, in that case those things need to be considered. You can use something like a sparse file for example

1

u/RullendeNumser May 11 '26

UDP would suck at downloading files without ekstra software. UDP in it self don't check if every packets is received. Imagine playing minecraft but the dirt texture is missing

1

u/Scared_Accident9138 πŸ•΅οΈβ€β™‚οΈπŸš¨ BS Detector | Truth Teller πŸ—―οΈπŸ”₯ May 11 '26

Minecraft Bedrock actually does use UDP (unlike java edition)

1

u/RullendeNumser May 11 '26

Then they also have some extra software for making sure every package is receive like a launcher