Going back to the times when I first started learning about information technology and networking, I have to say, I was pretty clueless. That's not to say I'm full of knowledge today, but my past self would definitely think I know something. I guess I can write about some of that knowledge. If anything, this can be a fun little project to help me solidify my knowledge.
What is the IP protocol?
We know a bit about the Internet Protocol (IP protocol). Never mind the fact that it's one of those weird redundancies like ATM machine. Let's learn a bit about what it is, so we can then start understanding what TCP and UDP are.
According to Wikipedia, the IP protocol is the "principal communications protocol in the internet protocol suite for relaying datagrams across network boundaries." Okay. That's a whole lot of words that probably make no sense. Really, it's just the protocol that delivers network packets.
Right now, we're all familiar with IPv4. You know, those 192.168.1.12-type addresses. Those in themselves are a blog post for another day. The main thing to keep in mind is that it's responsible for addressing host interfaces. You can read a bit more about the internet protocol here: RFC 791.
RFC 791 specifies that the "Internet Protocol is designed for use in interconnected systems of packet-switched computer communication networks." Furthermore, it "provides for transmitting blocks of data called datagrams from sources to destinations, where sources and destinations are hosts identified by fixed length addresses." That's where IP addresses come into play. Those 32-bit IPv4 addresses we talked about earlier? Yeah. That's a fixed-length address.
These datagrams can be fragmented and reassembled as well – the second of the two functions the protocol implements (the first being the addressing part). These are done with a sequence number. This way, the destination host can know how to reconstruct the datagrams.
That's a ton of information, and there's a ton more. Still, this kind of helps us understand some of the very basics of how things IP works.
Transmission Control Protocol (TCP) is the more common protocol we see. This is the protocol that breaks up those datagrams we talked about earlier and provides a way to identify those fragments for reassembly. This is important, as you want to ensure that the data is received correctly and completely. Data can be retransmitted if needed.
The thing you will read time and time again about TCP is that it's a connection-oriented protocol. This is important to know, because it's part of how the TCP three-way handshake works:
In this image I borrowed from Wikipedia, you can see how the TCP three-way handshake works. Basically, what happens is:
- The client (Alice) says, "Sup Bruh? Wanna chat?" to the server (Bob) and sends a TCP packet with a SYN (synchronize) flag. Just asking, "Hey, ya wanna connect?"
- Bob, the server, replies back with its own packet and a SYN and ACK (acknowledgement) flag set. This is like, "Fo' sho'! Here's my SYN and and ACK!"
- Alice receives Bob's SYN+ACK and sends back an ACK to confirm the connection.
Easy enough, eh?
UDP is like the derpy, connectionless protocol of the two. It stands for User Datagram Protocol, and doesn't really give a crap if the recipient acknowledges the received packets. It's just there like, "BRAARRGGHHH! Have packets!!!"
Meanwhile the receiving end is just there like, "Hmm? Okay. Um, whatever. I don't know if I received all the packets. I'll just take what I can get."
Sounds pretty crap, right? Well, it's useful for certain kinds of connections where speed is more important than error correction. You know, things like video, audio, voice, etc. Imagine if you were trying to make a voice call, but TCP was there like, "No wait, wait! WAIT! Hold up! I need to make sure .. Ah crap more packets! Wait! Chill! Ahh ... son of a...!" while you're just there enjoying a janky phone call. See? UDP, although the derpy of the two, has its purpose.
Update: Ghost says this is a three-minute read. Why the heck does it feel like it took three lifetimes to write?!