{"id":18253900,"url":"https://github.com/prempreetbrar/tcpfileprocessor","last_synced_at":"2025-10-04T03:27:41.466Z","repository":{"id":237105702,"uuid":"746349703","full_name":"prempreetbrar/TCPFileProcessor","owner":"prempreetbrar","description":"A program that processes a file over a TCP connection.","archived":false,"fork":false,"pushed_at":"2024-04-29T22:37:22.000Z","size":28903,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-08T21:46:34.047Z","etag":null,"topics":["bytebuffer","client-server","concurrency","echo-server","file-transfer","gzip-compression","gzip-decompression","java","multithreading","network-programming","socket-programming","tcp"],"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,"publiccode":null,"codemeta":null}},"created_at":"2024-01-21T19:45:41.000Z","updated_at":"2024-04-29T22:45:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"34aab0fb-b007-4e33-a637-b31f0ef03224","html_url":"https://github.com/prempreetbrar/TCPFileProcessor","commit_stats":null,"previous_names":["prempreetbrar/tcpfileprocessor"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/prempreetbrar/TCPFileProcessor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prempreetbrar%2FTCPFileProcessor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prempreetbrar%2FTCPFileProcessor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prempreetbrar%2FTCPFileProcessor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prempreetbrar%2FTCPFileProcessor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prempreetbrar","download_url":"https://codeload.github.com/prempreetbrar/TCPFileProcessor/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prempreetbrar%2FTCPFileProcessor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278259530,"owners_count":25957507,"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","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["bytebuffer","client-server","concurrency","echo-server","file-transfer","gzip-compression","gzip-decompression","java","multithreading","network-programming","socket-programming","tcp"],"created_at":"2024-11-05T10:08:57.911Z","updated_at":"2025-10-04T03:27:41.449Z","avatar_url":"https://github.com/prempreetbrar.png","language":"Java","readme":"# TCP File Processor\n\nA program that establishes a TCP connection with a remote server, sends a local file to the server for processing, and receives\nand stores the processed file in the local file system. Watch a GIF of me interacting with it below!\n\n![client](https://github.com/prempreetbrar/TCPFileProcessor/assets/89614923/1533699c-6171-4574-9650-a74570923d5b)\n\u0026nbsp;\n\n## Features\n- Server `ECHO`: The server sends back the same data it receives from the client without any modification.\n- Server `ZIP`: The server receives data from the client, compresses it using the GZIP format, and sends it back to the client.\n- Server `UNZIP`: The server receives GZIP compressed data from the client, decompresses it, and sends it back to the client.\n- The client opens a TCP `Socket` to communicate with the server; it first sends the service code provided as a command line argument to the server,\n  followed by the input file to be processed. At the same time (ie. simultaneously), it reads the server's processed file chunks from the `Socket` and\n  writes them to the output file. The server works analogously in the opposite direction (it reads the regular file from the `Socket`, processes it,\n  and writes to the `Socket`).\n- The server continues reading from its `Socket` input stream by repeatedly calling the `read()` method until it returns `-1` (indicating the stream is\n  at the end of the file). The client signals to the server that transmission is complete (allowing it to stop its reading) by calling `shutdownOutput()`\n  to close its side of the connection. The **client can no longer send but can still read the processed data** coming from the server (analogous to sending a segment\n  with `FIN = 1`); the client state goes from `ESTAB` -\u003e `FIN_WAIT1` -\u003e `FIN_WAIT2`. See the image below:\n\n![image](https://github.com/prempreetbrar/TCPFileProcessor/assets/89614923/10d15ddb-589d-4544-b915-8aa9eb05ef36)\nIn the above image, we see that the client can still receive data from the server even after sending a segment with `FIN = 1`. This is exactly what is happening in our \nprogram; the client closes its side of the connection after the entire file is sent, but continues reading the processed file from the server. \n  \n- Client uses a parallel rather than serial design to prevent deadlock; with a serial design, the client would need to transmit its entire file before reading from the server. For very large files, the client would not yet read anything from its `Socket`; the `Socket` buffer would quickly fill up with the server's processed data. This would then block the server when it calls `write()` on the `Socket` output stream (this is the flow control of TCP and is how the `Socket` is designed); a blocked server would not read from its `Socket` input stream, which then blocks the client. Both the client and server would be blocked, leading to a deadlock. The client uses two threads to work around this; one for sending data, and another for reading processed data.\n\n## Usage/Limitations\n### When Running the Client:\n- `-i \u003cinput_file\u003e` specifies the name of the file to be processed by the server; **REQUIRED**\n- `-o \u003coutput_file\u003e` specifies the name of the processed output file; defaults to `input_file.out`\n- `-c \u003cservice_code\u003e` specifies the service code requested from the server; `0` is `ECHO`, `1` is `GZIP`, `2` is `UNZIP`. Defaults to `1 (GZIP)`.\n- `-b \u003cbuffer_size\u003e` specifies the buffer size in _bytes_ used for writing the file to the server and reading processed data. Defaults to `10000`.\n- `-p \u003cport_number\u003e` specifies the server's port; default is `2025`.\n- `-s \u003cserver_name\u003e` specifies the server's hostname; default is `localhost`.\n\n### When Running the Server:\n- `-p \u003cport_number\u003e` specifies the server's port; default is `2025`; **the `-p` flags should match when running both the client and server. Otherwise, the client will be unable to connect.**\n- `-b \u003cbuffer_size\u003e` specifies the buffer size (in bytes) used at the server for read/write operations; default is `1000`.\n- `quit` shuts the server down if it is already running. \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/TCPFileProcessor/assets/89614923/55d0cd94-ae70-4650-9fb1-dffdda491cd2)\n\u0026nbsp;\n\n2. Unzip the code:\n\u003cbr\u003e\u003c/br\u003e\n![unzip](https://github.com/prempreetbrar/TCPFileProcessor/assets/89614923/5f2c3b0f-da1d-4ffe-90c5-91f50cd8dc83)\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/TCPFileProcessor/assets/89614923/612c3273-386f-4ae7-bbbc-ac837ae989b3)\n\u0026nbsp;\n\n4. Start the server by running `streamserver.jar`, as follows:\n   ```\n   cd server\n   java -jar streamserver.jar\n         [-b \u003cbuffer_size\u003e]\n         [-p \u003cport_number\u003e]\n   ```\n\u003cbr\u003e\u003c/br\u003e\n![server](https://github.com/prempreetbrar/TCPFileProcessor/assets/89614923/e107e8c4-6750-4b4d-9f2b-1f407d92a5a3)\n\u0026nbsp;\n\n5. Start the client by compiling all files and running `ClientDriver.java`, as follows:\n```\ncd client\njavac *.java\njava ClientDriver -i ../files/\u003cinput_file\u003e\n      [-o \u003coutput_file\u003e]\n      [-c \u003cservice_code\u003e]\n      [-b \u003cbuffer_size\u003e]\n      [-p \u003cport_number\u003e]\n      [-s \u003cserver_name\u003e]\n```\n\u003cbr\u003e\u003c/br\u003e\n![client](https://github.com/prempreetbrar/TCPFileProcessor/assets/89614923/c89d5a62-b4e4-4d9e-8b4c-aad27383d9f8)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprempreetbrar%2Ftcpfileprocessor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprempreetbrar%2Ftcpfileprocessor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprempreetbrar%2Ftcpfileprocessor/lists"}