this is common in the web environment (the client runs in the browser)
How do sockets work?
TCP uses three-way handshake for establishing the connection (see Zahájení spojení)
socket = virtual communication channel (with unique ID) created after handshake
after the connection is established, a socket with unique ID is created on both sides (client, server) - and it allows for continuous exchange of data (reading/writing)
connection reuse is very important (it speeds up the communication)
HTTP Keep-Alive
HTTP Pipelining
HTTP Keep-Alive (persistent connections)
HTTP Keep-Alive is an agreement not to close the connection between client and server after each request/response
because opening a new TCP connection is quite expensive (time-wise) - especially, when the server that I am trying to reach is geographically far away
reusing the same connection reduces latency and overhead with creating new TCP connections
with HTTP Keep-Alive, first request needs 2x RTT (round-trip time) and every other request needs 1xRTT
without it, it’s always 2xRTT for each request
the the time saved is (n−1)∗RTT, where n=amount_requests_sent
1xRTT = request - response
2xRTT = SYN - SYN ACK - ACK (+ request) - response
limitation: requests are processed sequentially, request is sent, waiting for response and then another request is sent etc.
DNS resolution: browser gets the IP address for the server
TCP three way handshake + creating the socket for communication
browser sends ACK and HTTP request
web servers passes the request to the running web application which serves the request and then sends the response back to the client
there could be more domains/websites on one physical web server thanks to VirtualHosts, the IP is the same and client uses Host header to pick the correct virtual host
HTTP is stateless, we are using different mechanisms to keep the state:
Authorization header is copied in every request
Cookies - small bits of information sent with the request to inform the server about the state (or to keep a Session = temporary storage of the state on the webserver side)
Hypertext - original HTTP design principle
app state is represented by resources (hypermedia) and links define transitions between states