{"id":18253902,"url":"https://github.com/prempreetbrar/tcpwebserver","last_synced_at":"2025-04-08T21:46:45.939Z","repository":{"id":235947507,"uuid":"772857603","full_name":"prempreetbrar/TCPWebServer","owner":"prempreetbrar","description":"A TCP server that serves files over the Internet in response to HTTP requests.","archived":false,"fork":false,"pushed_at":"2024-04-29T17:08:19.000Z","size":27997,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-14T17:15:16.379Z","etag":null,"topics":["concurrency","demultiplexing","http-get","http-server","java","multithreading","network-programming","non-persistent","server-side","socket-programming","tcp","tcp-server"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/prempreetbrar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-03-16T04:24:20.000Z","updated_at":"2024-04-29T17:08:22.000Z","dependencies_parsed_at":"2024-04-25T03:39:55.244Z","dependency_job_id":null,"html_url":"https://github.com/prempreetbrar/TCPWebServer","commit_stats":null,"previous_names":["prempreetbrar/tcpwebserver"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prempreetbrar%2FTCPWebServer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prempreetbrar%2FTCPWebServer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prempreetbrar%2FTCPWebServer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prempreetbrar%2FTCPWebServer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prempreetbrar","download_url":"https://codeload.github.com/prempreetbrar/TCPWebServer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247934808,"owners_count":21020724,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["concurrency","demultiplexing","http-get","http-server","java","multithreading","network-programming","non-persistent","server-side","socket-programming","tcp","tcp-server"],"created_at":"2024-11-05T10:08:59.353Z","updated_at":"2025-04-08T21:46:45.901Z","avatar_url":"https://github.com/prempreetbrar.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TCP Web Server\n\nA program that serves web objects from an existing directory to HTTP clients over the Internet using TCP. Watch\na GIF of me interacting with it below!\n\n![request](https://github.com/prempreetbrar/TCPWebServer/assets/89614923/44472d33-d81a-4b1a-a282-0cf861a3d654)\n\u0026nbsp;\n\n## Features\n- Supports HTTP `GET` requests. \n- Operates in non-persistent HTTP mode; once the object is served, the server closes the underlying TCP connection.\n- Handles multiple connections simultaneously using multi-threading; spawns a new thread and creates a new `Socket` for _each_\n  incoming TCP connection request (unlike UDP, where a single socket is used for all incoming requests and all messages are demultiplexed\n  to the _same_ socket). See the following image:\n\n\u003cbr\u003e\u003c/br\u003e\n![image](https://github.com/prempreetbrar/TCPWebServer/assets/89614923/69ed61dc-d2e5-4625-a177-134cf0b7cd6b)\n\u003cbr\u003e\u003c/br\u003e\nIn the above image, you see a service process `P1` open three different `Socket`s for three different connecting clients; every client's segments are demultiplexed to a different `Socket` at `P1`.\n  \n- To prevent non-responsive clients from hogging server resources, if the server does not receive an HTTP message from the\n  client after the initial 3-way handshake, the server closes the connection and sends an error message with status code `408`. Note that\n  this only occurs if the client is connecting using `telnet` or certain other application layer protocols. With something like a browser, the\n  handshake is automatically (ie. _implicitly_) followed by an HTTP request.\n- After server is shutdown, waits reasonable amount of time for current requests to be serviced before terminating.\n- If the server can recover from exceptions (ie. the exception only affected a worker thread), then the server continues with normal execution. Otherwise,\n  it terminates. \n\n## Usage/Limitations\n- The root directory of the web server, where the objects are located, is specified as a command line input parameter. If the object path in\n  the `GET` request is `/object-path`, then the file containing the object is located on the absolute path `server-root/object-path` in the file\n  system, where `server-root` is the root directory of the web server.\n- `-p \u003cport_number\u003e` specifies the server's port; default is `2025`\n- `-t \u003cidle_connection_timeout\u003e` specifies the time after which the server closes the TCP connection in **milli-seconds**; default is `0` (which means infinity,\n   ie. idle connections are not closed)\n- `-r \u003cserver-root\u003e` is the root directory of the web server (where all its HTTP objects are located); default is the current directory (directory in which program\n   is ran)\n- `quit` is typed in the system terminal to shut the server down. \n- Sends responses with HTTP version `HTTP/1.1`; only returns responses with the following status codes/phrases:\n  ```\n  200 OK\n  400 Bad Request\n  404 Not Found\n  408 Request Timeout\n  ```\n- Assumes all header lines in the HTTP request are formatted correctly; only an error in the HTTP request line can trigger a `400 Bad Request` error. A\n  properly formatted request line consists of three _mandatory_ parts which are separated by one or more spaces, as follows: `GET /object-path HTTP/1.1`.\n  The command `GET` and protocol `HTTP/1.1` are fixed, while the `object-path` is optional. If no `object-path` is provided, _ie._ the request only specifies \"/\",\n  then `index.html` is assumed by default. \n\n## If you want to start up the project on your local machine:\n1. Download the code as a ZIP:\n\u003cbr\u003e\u003c/br\u003e\n![download](https://github.com/prempreetbrar/TCPWebServer/assets/89614923/291dc4a0-fe63-40b8-a70a-8bd3f987d5b6)\n\u0026nbsp;\n\n2. Unzip the code:\n\u003cbr\u003e\u003c/br\u003e\n![unzip](https://github.com/prempreetbrar/TCPWebServer/assets/89614923/e2283434-6b61-41a1-b9b9-bb6380900798)\n\u0026nbsp;\n\n3. Open the folder in an IDE, such as VSCode:\n\u003cbr\u003e\u003c/br\u003e\n![open](https://github.com/prempreetbrar/TCPWebServer/assets/89614923/aa1e0040-15af-4697-b9ab-52104b28e5b4)\n\u0026nbsp;\n\n4. Start the server by compiling all files and then running `ServerDriver.java`, as follows:\n   ```\n   javac *.java\n   java ServerDriver -p \u003cport_number\u003e -t \u003cidle_connection_timeout\u003e -r \u003cserver_root\u003e\n   ```\n\u003cbr\u003e\u003c/br\u003e\n![server](https://github.com/prempreetbrar/TCPWebServer/assets/89614923/51398c4c-fa7b-4867-b6b9-0b3d40d2bf55)\n\u0026nbsp;\n\n5. Send a request to the server using `telnet`, a web browser, or any other application layer protocol:\n\u003cbr\u003e\u003c/br\u003e\n![request](https://github.com/prempreetbrar/TCPWebServer/assets/89614923/44472d33-d81a-4b1a-a282-0cf861a3d654)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprempreetbrar%2Ftcpwebserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprempreetbrar%2Ftcpwebserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprempreetbrar%2Ftcpwebserver/lists"}