sockets.
md 2025-05-19
SOCKETS
sockets is a vertaul endpoint for sending or receiving data between devices over a network (like the
phone line).
what makes up a socket
ip address of the host.
port number.
tranport protocol.
host name (like [Link]).
[Link]:80 using TCP → This refers to the HTTP server on that IP.
types of sockets
server sockets : listens to incoming connecitons.
client sockets : initiate the connection to the server.
how it works (for tcp)
the server creates a socket and start listening.
client creates socket and connect to the ip:port of the server.
tcp performs the 3-way-handshake.
both use their sockets to send and recive data.
when done both close the socket.
tcp socket lifecycle
1. both server and client created socket but without bound or connect.
2. the server binds the socket to a local ip and port.
3. the server starts listening for incomming connections.
4. the client tries to connect with the server socket.
5. before starting exchages both agree on communication with 3-way-handshake <SYN:client,
SYN+ACK:server, ACK:client>.
6. now both sides can send and recieve data.
7. connection termination (one side startt to close connection with 4-step process <FIN:client,
ACK:server, FIN:server, ACK:client>)
udp socket lifecycle
same as tcp but there is no connection established, no 3-way-hanshake, no order.
1. creates socket.
2. bind to ip/port.
3. send/receive.
4. close socket.
1/1