A program that downloads a file from the Internet given a URL over TCP. Watch a gif of me interacting with it below!
- Supports both
HTTP
andHTTPS
URLs; if the protocol isHTTP
, a regularSocket
is used to establish a TCP connection; if the protocol isHTTPS
, a secure connection is established with the server using anSSLSocket
. - Operates in non-persistent HTTP mode; once the object is downloaded, the client closes the underlying TCP connection.
- URLs must be properly formatted with the following syntax:
protocol://hostname[:port]/pathname
, whereprotocol
is either HTTP or HTTPS,hostname
is the name of the web server,[:port]
is an optional part which specifies the server port (default is 80 for HTTP and 443 for HTTPS),pathname
is the path of the requested object on the specified host. - Reads the server response line by line to first identify the end of the header fields (by looking for
\r\n
), and then reads the remainder of the server's response (the file itself) chunk-by-chunk using a buffer for improved performance.
-
Obtain the URL of a file from the internet, copy it. Then, run the code by doing
java ClientDriver -u <url_copied_from_internet>