{"id":23137690,"url":"https://github.com/p4zd4n/distributed-averaging-system","last_synced_at":"2026-04-18T05:34:11.294Z","repository":{"id":263890590,"uuid":"891632470","full_name":"P4ZD4N/distributed-averaging-system","owner":"P4ZD4N","description":"App to calculate the average of collected from various instances numerical data and to transfer it between devices in the local network using UDP protocol ","archived":false,"fork":false,"pushed_at":"2024-11-28T14:18:14.000Z","size":738,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-04T09:45:54.655Z","etag":null,"topics":["client","java","network-programming","server","sockets","udp"],"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/P4ZD4N.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-11-20T17:14:26.000Z","updated_at":"2024-11-28T14:18:18.000Z","dependencies_parsed_at":"2025-04-04T09:42:59.380Z","dependency_job_id":"31b97490-1ebe-4c65-a339-8ce16143d7f9","html_url":"https://github.com/P4ZD4N/distributed-averaging-system","commit_stats":null,"previous_names":["p4zd4n/distributed-averaging-system"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/P4ZD4N/distributed-averaging-system","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/P4ZD4N%2Fdistributed-averaging-system","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/P4ZD4N%2Fdistributed-averaging-system/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/P4ZD4N%2Fdistributed-averaging-system/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/P4ZD4N%2Fdistributed-averaging-system/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/P4ZD4N","download_url":"https://codeload.github.com/P4ZD4N/distributed-averaging-system/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/P4ZD4N%2Fdistributed-averaging-system/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31957669,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T00:39:45.007Z","status":"online","status_checked_at":"2026-04-18T02:00:07.018Z","response_time":103,"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":["client","java","network-programming","server","sockets","udp"],"created_at":"2024-12-17T13:08:39.728Z","updated_at":"2026-04-18T05:34:11.254Z","avatar_url":"https://github.com/P4ZD4N.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 💻 Distributed Averaging System\n\n## 👀 About\n\nDistributed Averaging System is app that operates in two modes: master and slave. The purpose of the application is to collect numerical data from various instances of the program and calculate the average of these numbers. The application uses the UDP communication protocol to transfer data between devices in the local network.\n\n## 📋 How the application works\n\n### General\n\nThe application consists of, among others, a program implementing the DAS (Distributed Averaging\nSystem) started with the command:\n```bash\njava DAS \u003cport\u003e \u003cnumber\u003e\n```\nwhere ```\u003cport\u003e``` is a number specifying the UDP port number and ```\u003cnumber\u003e``` is an integer.\nThe application works in two modes: master and slave. The mode selection is automatic\nwhen the application is launched based on the current system state and the specified state\nparameter. When launched, the application tries to create a UDP socket by opening a\nUDP port with the number given by the ```\u003cport\u003e``` parameter. This operation can have two results:\n\n- The application succeeds to open the requested port. This is where the app comes in\nin **master mode**.\n- The application fails to open the port because it is already occupied. In this case, the application\nstarts working in **slave mode**.\n\n### Master mode\n\nApplication working in master mode remembers value passed as the  ```\u003cnumber\u003e``` parameter\nand then receives messages cyclically in a loop through the socket on port ```\u003cport\u003e```. Next application operations depends on value of the number received in the message:\n\n- If this value is different than ```0``` and ```-1```, the process writes this value to the console and remembers it.\n- If this value is ```0```, the process:\n\t*  Calculates the average value of all non-zero numbers received from start of work, including the ```\u003cnumber\u003e``` value.\n\t* Writes average value to the console.\n\t* Using the socket, on which it is working, it sends a broadcast message to all computers in its local network to port number ```\u003cport\u003e``` (the same one, on which it works on) containing the calculated average value.\n- If this value is ```-1```, the process:\n\t* Writes this value to the console.\n\t* Using the socket, on which it is working, it sends a broadcast message to all computers in its local network to port number ```\u003cport\u003e``` (the same one, on which it works on) containing ```-1``` value.\n\t* Closes the socket and ends work.\n\n### Slave mode\n\nAn application working in slave mode creates a UDP socket by opening a random UDP port\nnumber (relying on the operating system in this respect) and then using\nthis socket, sends it to a process working on the same machine on port number\n```\u003cport\u003e``` message containing the value of the ```\u003cnumber\u003e``` parameter. After doing this\nthe process terminates.\n\n## 🔧 Tech Stack\n\n- Java 8\n- Bash\n\n## ▶️ Run\n\nClone the project\n\n```bash\ngit clone git@github.com:P4ZD4N/distributed-averaging-system.git\n```\n\nNavigate to the project source directory\n\n```bash\ncd /path/to/distributed-averaging-system/src\n```\n\nCompile DAS class\n\n```bash\njavac DAS.java\n```\n\nRun app\n\n```bash\njava DAS \u003cport\u003e \u003cnumber\u003e\n```\n\n## ⚙️ Bash scripts\n\nI created two additional bash scripts: `sender.sh` and `sniffer.sh`. They are intended for working with app from other computers in our local network (from any computer on which we do not have instance of master yet). \n\n`sender.sh`\nThis script can help you with sending numbers to the master from different computer. If you know IP address of the computer, on which the master is running and port, on which it receives the numbers. Usage:\n```bash\n./sender.sh \u003cip_address\u003e \u003cport\u003e \u003cnumber_to_send\u003e\n```\n\n\u003cbr\u003e\n\n`sniffer.sh`\nBecause master sends a broadcast message to all computers in its local network on the port, on which it works, we have opportunity to receive such messages on different computer. We can do it using this script. Usage:\n```bash\n./sniffer.sh \u003cport\u003e\n```\n\n## 📺 Demo\n\nGIF below presents compilation of app and running it in master mode on port 3000. 10 is first number, which is remembered by master.\n![](./demo/1.gif)\n\nGIF below presents running app in slave mode, because port 3000 is already occupied. 15 and 25 is sending to master and remembered.\n![](./demo/2.gif)\n\nGIF below presents running sender and sniffer scripts on different computer. Firstly (with invocation of sender) script sends 50 to master. Next, sniffer is waiting for messages broadcasted by master.\n![](./demo/3.gif)\n\nGIF below presents running app in slave mode to send 0 and -1 numbers. 0 causes the average calculated from all numbers received so far to be broadcast. -1 shuts down app.\n![](./demo/4.gif)\n\nImage below presents effect of sending 0 and -1, which was shown on previous GIF. As you can see sniffer received both messages broadcasted by master.\n![](./demo/5.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fp4zd4n%2Fdistributed-averaging-system","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fp4zd4n%2Fdistributed-averaging-system","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fp4zd4n%2Fdistributed-averaging-system/lists"}