{"id":24068809,"url":"https://github.com/lazydoomslayer/rust-websocket-server","last_synced_at":"2025-02-26T20:23:34.237Z","repository":{"id":269886035,"uuid":"908722309","full_name":"LazyDoomSlayer/rust-websocket-server","owner":"LazyDoomSlayer","description":"A secure and efficient WebSocket server built with Rust, featuring real-time communication and extensible architecture.","archived":false,"fork":false,"pushed_at":"2024-12-26T19:44:52.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-09T13:48:15.549Z","etag":null,"topics":["asynchronous-programming","networking","real-time-communication","rust-server","tokio","websocket-server"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/LazyDoomSlayer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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-12-26T19:39:48.000Z","updated_at":"2024-12-26T22:26:45.000Z","dependencies_parsed_at":"2024-12-26T23:19:24.054Z","dependency_job_id":"3c6c2ed8-7f37-436c-8a9c-db66334bbf2f","html_url":"https://github.com/LazyDoomSlayer/rust-websocket-server","commit_stats":null,"previous_names":["lazydoomslayer/rust-websocket-server"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LazyDoomSlayer%2Frust-websocket-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LazyDoomSlayer%2Frust-websocket-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LazyDoomSlayer%2Frust-websocket-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LazyDoomSlayer%2Frust-websocket-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LazyDoomSlayer","download_url":"https://codeload.github.com/LazyDoomSlayer/rust-websocket-server/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240927592,"owners_count":19879957,"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":["asynchronous-programming","networking","real-time-communication","rust-server","tokio","websocket-server"],"created_at":"2025-01-09T13:47:34.918Z","updated_at":"2025-02-26T20:23:34.200Z","avatar_url":"https://github.com/LazyDoomSlayer.png","language":"Rust","readme":"# Rust WebSocket Server\n\nA lightweight WebSocket echo server built in **Rust** using **Tokio** and **tokio-tungstenite**. This server listens for WebSocket connections, processes messages based on the endpoint, and provides multiple functionalities.\n\n---\n\n## Features\n\n- **Concurrent WebSocket Clients**: Supports multiple WebSocket clients simultaneously.\n- **Echo Functionality**: Automatically echoes back text and binary messages.\n- **Mathematical Operations**: Provides an endpoint for solving basic math operations.\n- **Global Chat**: Facilitates a simple chat feature for connected clients.\n- **Asynchronous and Efficient**: Powered by **Tokio** for high performance.\n- **Docker Support**: Easily deployable using Docker for any environment.\n- **Modular and Extensible**: Clean Rust codebase for adding new features.\n\n---\n\n## Requirements\n\n- **Rust** (version `1.70+`)\n- **Cargo** (Rust's package manager)\n- **Docker** (for containerized deployment)\n\n---\n\n## Installation\n\n1. Clone the repository:\n\n   ```bash\n   git clone https://github.com/LazyDoomSlayer/rust-websocket-server.git\n   cd rust-websocket-server\n   ```\n\n2. Build the project:\n\n   ```bash\n   cargo build --release\n   ```\n\n---\n\n## Running Locally\n\n1. Start the WebSocket server:\n\n   ```bash\n   cargo run\n   ```\n\n2. The server will start on `ws://0.0.0.0:8765`.\n\n3. Test the server using a WebSocket client. For example, with [wscat](https://github.com/websockets/wscat):\n\n   ```bash\n   npm install -g wscat\n   ```\n\n4. Connect to different endpoints:\n\n   ### `/echo`\n\n   - Establish a connection:\n\n     ```bash\n     wscat -c ws://0.0.0.0:8765/echo\n     ```\n\n   - Send a message:\n\n     ```text\n     \u003e Hello, WebSocket!\n     ```\n\n     The server will echo it back:\n\n     ```text\n     \u003c Echo: Hello, WebSocket!\n     ```\n\n   ### `/math`\n\n   - Perform mathematical operations:\n\n     ```bash\n     wscat -c ws://0.0.0.0:8765/math\n     ```\n\n   - Example interactions:\n\n     ```text\n     \u003e 8 - 2\n     \u003c Result: 6\n     \u003e 10 + 2\n     \u003c Result: 12\n     \u003e 10 * 2\n     \u003c Result: 20\n     \u003e 3!\n     \u003c Result: 6\n     ```\n\n   ### `/global-chat`\n\n   - Engage in a global chat:\n\n     ```bash\n     wscat -c ws://0.0.0.0:8765/global-chat\n     ```\n\n   - Example chat:\n\n     ```text\n     \u003e Hello Somebody\n     \u003c Greeting from somebody\n     \u003e My name is Jeff\n     \u003c My name is John\n     ```\n\n---\n\n## Running with Docker\n\nYou can also run the server in a Docker container:\n\n1. Build the Docker image:\n\n   ```bash\n   docker build -t websocket-echo-server .\n   ```\n\n2. Run the container:\n\n   ```bash\n   docker run -p 8765:8765 websocket-echo-server\n   ```\n\n3. The server will be available at `ws://\u003cyour-docker-host\u003e:8765`.\n\n---\n\n## Dependencies\n\nThis project uses the following Rust crates:\n\n- [`tokio`](https://crates.io/crates/tokio): Asynchronous runtime.\n- [`tokio-tungstenite`](https://crates.io/crates/tokio-tungstenite): WebSocket implementation for Tokio.\n- [`futures-util`](https://crates.io/crates/futures-util): Utilities for working with asynchronous streams.\n- [`tracing`](https://crates.io/crates/tracing): For structured logging.\n- [`http`](https://crates.io/crates/http): Utilities for working with HTTP requests and responses.\n- [`uuid`](https://crates.io/crates/uuid): For generating and handling UUIDs, especially useful for unique client or session identifiers.\n\n---\n\n## Code Structure\n\n- **`main.rs`**: Contains the main WebSocket server logic, including:\n  - Setting up the TCP listener.\n  - Accepting WebSocket connections.\n  - Handling `/echo`, `/math`, and `/global-chat` endpoints.\n\n---\n\n## Extending the Server\n\nEnhance the server by:\n\n1. **Secure Communication**:\n   - Add WSS support with `tokio-rustls`.\n\n---\n\n## Example Output\n\nWhen running the server, the output will look like this:\n\n```plaintext\nINFO  WebSocket server started successfully on ws://0.0.0.0:8765\nINFO  /echo is ready to be listened to...\nINFO  Incoming connection on path: /echo\nINFO  Echo handler invoked\nINFO  Received: Text(\"Hello, WebSocket!\")\nINFO  Echo connection closed\n```\n\n---\n\n## Contributions\n\nContributions are welcome! Feel free to submit issues or pull requests to improve the project.\n\n---\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flazydoomslayer%2Frust-websocket-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flazydoomslayer%2Frust-websocket-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flazydoomslayer%2Frust-websocket-server/lists"}