{"id":22537874,"url":"https://github.com/khaledashrafh/router-simulator","last_synced_at":"2025-10-17T02:30:44.151Z","repository":{"id":85810128,"uuid":"457835345","full_name":"KhaledAshrafH/Router-Simulator","owner":"KhaledAshrafH","description":"This project simulates a limited number of devices connected to a router's Wi-Fi using Java threading and semaphores. The router is designed to limit the number of open connections, allowing only a fixed number of devices to connect simultaneously. When the maximum number of connections is reached, incoming devices must wait until an existing conne","archived":false,"fork":false,"pushed_at":"2023-08-07T17:47:02.000Z","size":36,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-07T11:09:02.591Z","etag":null,"topics":["conccurency","devices","java-threads","router","semaphore","simulation","synchronization"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KhaledAshrafH.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-02-10T15:25:23.000Z","updated_at":"2024-06-06T23:14:52.000Z","dependencies_parsed_at":"2023-03-10T22:15:16.591Z","dependency_job_id":null,"html_url":"https://github.com/KhaledAshrafH/Router-Simulator","commit_stats":null,"previous_names":["khaledashrafh/router-simulator"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KhaledAshrafH%2FRouter-Simulator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KhaledAshrafH%2FRouter-Simulator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KhaledAshrafH%2FRouter-Simulator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KhaledAshrafH%2FRouter-Simulator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KhaledAshrafH","download_url":"https://codeload.github.com/KhaledAshrafH/Router-Simulator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236765516,"owners_count":19201287,"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":["conccurency","devices","java-threads","router","semaphore","simulation","synchronization"],"created_at":"2024-12-07T11:09:05.134Z","updated_at":"2025-10-17T02:30:38.768Z","avatar_url":"https://github.com/KhaledAshrafH.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Router-Simulator with Java Threading and Semaphore\n\nThis project simulates a limited number of devices connected to a router's Wi-Fi using Java threading and semaphores. The router is designed to limit the number of open connections, allowing only a fixed number of devices to connect simultaneously. When the maximum number of connections is reached, incoming devices must wait until an existing connection is released.\n\n## Overview\n\nThe Router Simulation project demonstrates how semaphores can be used to limit the number of concurrent connections in a router's Wi-Fi system. It provides a simplified model of a router and devices connecting to it. The simulation is implemented in Java and utilizes threading and semaphores for synchronization.\n\nThe project consists of the following classes:\n\n1. **Router**: Manages the router's connections and provides methods to occupy and release connections.\n\n2. **Semaphore**: Implements a semaphore, a synchronization primitive used to control access to a shared resource. The router uses the semaphore to limit the number of concurrent connections.\n\n3. **Device**: Represents a device that can connect to the router. Each device is implemented as a separate thread and performs connection, online activity, and disconnection actions.\n\n4. **Network**: Contains the main method of the program. It prompts the user for input, creates device threads, and starts the simulation.\n\n## Installation\n\nTo run the Router Simulation, follow these steps:\n\n1. Clone the GitHub repository:\n```\ngit clone https://github.com/KhaledAshrafH/Router-Simulator\n```\n\n2. Open the project in your preferred Java development environment.\n\n3. Build the project to compile the source code.\n\n4. Run the project, and the simulation will start.\n\n## Usage\n\nUpon running the Router Simulation, you will be prompted to provide the following information:\n\n1. Enter the maximum number of Wi-Fi connections the router can accept.\n\n2. Enter the total number of devices that wish to connect.\n\n3. For each device, enter the device name and type.\n\nAfter providing the necessary input, the simulation will start, and the output will be displayed in the console.\n\n## Simulation\n\nThe simulation follows the rules outlined below:\n\n- The Wi-Fi connections are initially empty.\n\n- If a client is logged in and can be served (i.e., a connection is available), the client performs the following activities: connect, perform online activity, and log out.\n\n- If a client arrives and all connections are occupied, the client must wait until a connection becomes available.\n\n- After a client finishes their service, they leave, and one of the waiting clients (if any) connects to the internet.\n\nThe simulation output consists of messages that indicate the arrival of devices, connection status, log in/out activities, and online activities.\n\n## Sample Output\n\n**Sample Input:**\n```\nWhat is the number of Wi-Fi Connections?\n2\nWhat is the number of devices Clients want to connect?\n4\nDevice 1 Name: Khaled\nDevice 1 Type: Mobile\nDevice 2 Name: Mahmoud\nDevice 2 Type: Tablet\nDevice 3 Name: Passant\nDevice 3 Type: PC\nDevice 4 Name: Salma\nDevice 4 Type: Laptop\n```\n\n**Sample Output:**\n```\nKhaled (Mobile) arrived\nMahmoud (Tablet) arrived\nConnection 1: Khaled Occupied\nConnection 2: Mahmoud Occupied\nSalma (Laptop) arrived and waiting\nPassant (PC) arrived and waiting\nConnection 1: Khaled login\nConnection 1: Khaled performs online activity\nConnection 2: Mahmoud login\nConnection 2: Mahmoud performs online activity\nConnection 1: Khaled Logged out\nConnection 1: Salma Occupied\nConnection 1: Salma log in\nConnection 1: Salma performs online activity\nConnection 2: Mahmoud Logged out\nConnection 2: Passant Occupied\n```\n\n## Contributing\n\nContributions to the Router Simulation project are welcome. If you have any ideas, improvements, or bug fixes, please submit a pull request. For major changes, please open an issue first to discuss the proposed changes.\n\n\n## Conclusion\n\nThe Router Simulation with Java Threading and Semaphore project provides a practical implementation of a router simulation using Java threading and semaphores. By simulating the behavior of devices connecting, performing online activities, and disconnecting, the project demonstrates how to control the number of concurrent connections and manage resource allocation in a multithreaded environment.\n\nThe project's modular structure and clear separation of responsibilities make it easy to understandand extend. The use of semaphores ensures that the maximum number of connections is not exceeded, allowing devices to wait until a connection becomes available.\n\nThe included GUI enhances the user experience by providing a user-friendly interface for input and displaying the simulation output. The simulation output provides valuable insights into the order of execution and the activities performed by each device.\n\n\n## License\n\nThe Router Simulation project is licensed under the [MIT License](LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhaledashrafh%2Frouter-simulator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkhaledashrafh%2Frouter-simulator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhaledashrafh%2Frouter-simulator/lists"}