looks like just sockets, it is a ctu a lly a ssuming th a t the server spe a ks HTTP • HTTP uses CRLF (\r\n) • HTTP/1.1 requires a Host he a der • The expect a GET • The server decides when to close the connection 👉 Sockets don’t know a ny of this. 👉 The protocol does. ➡ Sockets a nswer how bytes move. ➡ Protocols a nswer wh a t those bytes me a n ➡ Every time we t a lk to a di ff erent server, we must follow their rules
out.write("GET / HTTP/1.1\r\nHost: ...".getBytes()); To this: URL url = new URL("http://example.com"); HttpURLConnection con =(HttpURLConnection) url.openConnection(); ➡ Good softw a re hides protocol complexity behind objects
a lpoly.edu using port 80 (HTTP pl a in text) ➡ Use a socket to connect to www.c a lpoly.edu using port 443 (HTTP over encryption) ➡ Use a n HttpConnection to connect to www.c a lpoly.edu (no port needed) ➡ Use a socket to connect to www.j a viergs.com using port 80 (HTTP pl a in text) ➡ Use a n HttpConnection to connect to www.j a viergs.com (no port needed ✏ Expl a in your results
Computing Javier Gonzalez-Sanchez, Ph.D. [email protected] Winter 2026 Copyright. These slides can only be used as study material for the class CSC 364 at Cal Poly. They cannot be distributed or used for another purpose. 32