Networking Basics
- Every machine that needs to communicate over the internet, needs a public address (IP address - Internet Protocol Address), which allows us to specify where we want our msgs / data to go
- IPv4 Address is a 32 bit integer → 4 billion unique IP addresses
- IPv6 → 128 bits → Will probably never reach the limit
- For two machines to communicate, we need each ones unique identifier (IP address), and it’s like sending mail in real life (to.. from… address.., etc)
- Internet Protocol → Rules for communicating between machines online
- IP Packet → Has the data that is being sent, and the header contains the metadata (to, from, where, etc)
- The mechanism / service which allows communication to be structured, ordered, is done thru TCP (Transmission Control Protocol)
- TCP breaks it down into more TCP header, which contains the information which allows it to re-assemble all of the data once reached destination
- The actual data which is inside of the packets, is called the application data
- When we send HTTP requests, this is where the data is stored, and what we actually work with as a dev
- There are so many protocols going on (IP, HTTP, TCP), is because these are handled by different parts of the networking layers.
Routers and Misc
- Each of our device does not need to have a public IP address, but our router does
- This is b/c router can manage the traffic / DNS query on behalf of our devices
- Static IP address → IP addresses that do not change (i.e. think of printers in office, or fax machines, etc)
- Dynamic IP addresses → Dynamic DNS, we usually have clients as dynamic IP addresses as they’re always connecting / leaving
- Ports → Channel of communication between machines (besides networks); a 2^16 value → Approximately about 6500 ports available / machine
- Can’t have multiple applications / pages running on same port
- i.e. https is reserved for port 443, and http is reserved for port 80
- local host is IP address 127.0.0.1, etc
TCP And UDP
- TCP establishes a connection between the two machines, which can now send data both ways → To do this, it does a 3-way connection (Send a msg to the server, server sends a response back, and then we send another msg from client to the server acknowledging it)
- TCP is reliable, but it’s slower because of the 3way handshake
- Exclusive pros:
- Reliability → Re-transmission of lost packets (if a specific packet wasn’t received, it’ll ONLY resend that ONE lost / corrupt packet.
- Keeping track of the order so we can re-assemble
- Examples which use TCP: HTTP (Web), Secure Mail Transfer Protocol (Emails), WS, etc
- UDP does not set up a handshake!
- Not reliable → If a certain packet doesn’t arrive, its lost forever!
- Data might arrive out of order too! → UDP does not correct them
- However, UDP is ALOT faster than TCP
- UDP is used in streaming data in real time (Live streaming a video, or a call, playing online games, DNS, etc)
- This means that its ok even if it lags a bit, or if a frame is glitched/out of order
- No need to re-send those frames as we’re watching this live
DNS