2 - Communication and Sockets Flashcards
(15 cards)
What is unicast and multicast?
Unicast - message to 1 receiver
Multicast - message to 1+ receiver
Write down the flow diagram of sockets
Create socket (CS)
bind to socket (S)
connect to server (C)
listen on socket (S)
accept connection (S)
send/receive loop (CS)
What happens when you fetch a webpage on the socket level?
1) Open socket to port 80 on a server
2) Send it an HTTP request
3) Wait for response
4) Server closes connection
What encoding do sockets send?
Binary (used instead of text when bandwidth is limited, or battery life needs to be saved)
What are things in binary that we can’t encode (at least for free) and how do we fix it?
Circular linked list, file-like objects (socket/etc)
To fix, have an “encode” function to flatten object
Describe when multicast is useful, and its limitations
Useful for: Needing to talk to many servers (Twitch, video game multiplayer servers)
Limitations: Sent out of order, no acks, data loss
What are the pros and cons of polling for a server?
Pros:
can still doing some things while loading/waiting, can get whatever is there (even if just a little bit) e.g. low quality YouTube video
Cons:
- possible infinite loop, high CPU usage maybe
What’s the third option that’s not blocking or non-blocking?
Block to sync, if something weird happens, timeout socket to close
In a very general and lazy sense, when to use TCP and UDP?
TCP does things for us on the protocol level that we don’t have to worry about
Use UDP when TCP is not suitable
How to get message back with UDP?
Along with your message, send your return address (also could be anything, DOSing)
- TCP does this already
What’s the function for TCP to keep a connection?
Select! Allows to keep sending messages as they wish. Select unblocks when something happens
What are the TCP advantages?
1) Connection-oriented
2) Reliable, delivery and order is guaranteed
- Generally used for most applications
What are the TCP disadvantages?
- more bandwidth (lots of protocol overhead)
- no broadcast/multicast support
- slower than UDP
What are the UDP advantages?
- connectionless (no 3-way handshake)
- support multicast
- fast + lighter than TCP
- support live/real-time data transmission
What are the UDP disadvantages?
- messages can be out of order
- unreliable data transfer
- usually treated as less important by router than TCP