{"id":24017702,"url":"https://github.com/sungj921028/rt-chat-room","last_synced_at":"2026-04-28T00:33:01.055Z","repository":{"id":270593463,"uuid":"910845174","full_name":"SunGj921028/RT-chat-room","owner":"SunGj921028","description":"A real time chat room with server and client design, supplies a lot of implementations.","archived":false,"fork":false,"pushed_at":"2025-11-20T07:31:03.000Z","size":2180,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-20T09:25:04.510Z","etag":null,"topics":["c","chatroom","client-server","communication","cpp","network","streaming"],"latest_commit_sha":null,"homepage":"","language":"C++","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/SunGj921028.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,"zenodo":null}},"created_at":"2025-01-01T15:58:45.000Z","updated_at":"2025-11-20T07:31:07.000Z","dependencies_parsed_at":"2025-06-12T22:38:48.509Z","dependency_job_id":"0095acb0-2969-4dd0-b675-425764ff0dbd","html_url":"https://github.com/SunGj921028/RT-chat-room","commit_stats":null,"previous_names":["sungj921028/rt-chat-room"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/SunGj921028/RT-chat-room","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SunGj921028%2FRT-chat-room","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SunGj921028%2FRT-chat-room/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SunGj921028%2FRT-chat-room/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SunGj921028%2FRT-chat-room/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SunGj921028","download_url":"https://codeload.github.com/SunGj921028/RT-chat-room/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SunGj921028%2FRT-chat-room/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32361477,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-27T20:07:02.737Z","status":"ssl_error","status_checked_at":"2026-04-27T20:07:00.910Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["c","chatroom","client-server","communication","cpp","network","streaming"],"created_at":"2025-01-08T09:42:37.838Z","updated_at":"2026-04-28T00:33:01.042Z","avatar_url":"https://github.com/SunGj921028.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RT-chat-room\n\n以 C++ 實作的即時通訊系統，聚焦在「**多用戶併發 + 安全通訊 + 多媒體傳輸**」三件事：\n\n- TLS 加密的 client-server 通訊\n- thread pool 架構下的多 client 連線處理\n- 訊息、檔案、音訊三種資料型態的 relay\n\n\u003e Demo Video: [YouTube](https://www.youtube.com/watch?v=BcTFOp-aB6Y)（建議 0.75x）\n\n---\n\n## Project Highlights\n\n- **Secure by default**: 所有資料透過 OpenSSL TLS 通道傳輸\n- **Concurrent server design**: `accept()` + thread pool，最多同時處理 10 位 client\n- **Real-time relay model**: client-client 溝通由 server 轉發，降低點對點連線複雜度\n- **Multimodal transport**: 文字訊息、檔案（`txt`/`md`）、音訊（`wav`）\n- **Integrity check for relayed files**: 使用 SHA-256 驗證轉傳檔案完整性\n\n---\n\n## Tech Stack\n\n- **Language**: C++\n- **Network**: POSIX Socket (`AF_INET`, `SOCK_STREAM`)\n- **Security**: OpenSSL (`SSL/TLS`, cert verification)\n- **Concurrency**: POSIX Threads (`pthread`), worker pool\n- **Audio Playback**: `aplay` (`alsa-utils`)\n- **Build**: `Makefile`\n\n---\n\n## System Architecture\n\n```text\n┌───────────────┐        TLS         ┌────────────────────────────┐         TLS        ┌───────────────┐\n│   Client A    │ \u003c----------------\u003e │           Server           │ \u003c----------------\u003e │   Client B    │\n└───────────────┘                    │ - Connection manager       │                    └───────────────┘\n┌───────────────┐        TLS         │ - ThreadPool (workers)     │         TLS        ┌───────────────┐\n│   Client C    │ \u003c----------------\u003e │ - UserManager              │ \u003c----------------\u003e │   Client D    │\n└───────────────┘                    │ - File/Audio relay pipeline│                    └───────────────┘\n                                     └────────────────────────────┘\n```\n\n### Core Modules\n\n- `server.cpp`, `server.hpp`\n  - 啟動 socket lifecycle（`socket -\u003e bind -\u003e listen -\u003e accept`）\n  - 建立 TLS server context（載入 `server.crt`、`server.key`）\n  - 控制連線上限 `MAX_CLIENTS`\n- `ThreadPool.cpp`, `ThreadPool.hpp`\n  - worker queue 處理 client 任務\n  - 指令解析與 6 種 send mode 的處理/轉發邏輯\n- `UserManager.cpp`, `UserManager.hpp`\n  - 註冊、登入、登出與在線狀態管理\n  - socket 與 username 的映射\n- `myfile.cpp`, `myfile.hpp`\n  - chunk/frame 收送\n  - client-\u003eclient 檔案轉傳與 hash 驗證\n  - 音訊串流與播放\n- `defAndFuc.cpp`, `defAndFuc.hpp`\n  - 共用常數、輸出訊息、CLI 選單、工具函式\n\n---\n\n## Feature Set\n\n### 1) Authentication\n\n- `register \u003cusername\u003e \u003cpassword\u003e`\n- `login \u003cusername\u003e \u003cpassword\u003e`\n- `logout`\n- `exit`（已登入時需先 logout）\n\n### 2) Messaging\n\n- Client -\u003e Server 訊息送達\n- Client -\u003e Client 私訊（經 server relay）\n\n### 3) File Transfer\n\n- 支援 `txt`、`md`\n- Client -\u003e Server 與 Client -\u003e Client\n- `EOF` 作為傳輸結束訊號\n- 轉傳檔案會附上 hash metadata 並由接收端驗證完整性\n\n### 4) Audio Streaming\n\n- 支援 `wav`\n- frame-based 傳輸（`FRAME_SIZE = 8192`）\n- 接收端透過 `aplay -` 即時播放\n\n---\n\n## Command Flow\n\n當輸入 `send` 後，可選擇 6 種模式：\n\n1. `send \u003cmessage\u003e`  \n   傳訊息給 server\n2. `send \u003ctarget_username\u003e \u003cmessage\u003e`  \n   傳訊息給指定 client\n3. `send \u003cfilePath\u003e`  \n   傳檔案給 server\n4. `send \u003ctarget_username\u003e \u003cfilePath\u003e`  \n   傳檔案給指定 client\n5. `send \u003caudioPath\u003e`  \n   傳音訊給 server\n6. `send \u003ctarget_username\u003e \u003caudioPath\u003e`  \n   傳音訊給指定 client\n\n---\n\n## Run Locally\n\n### Requirements\n\n- Linux (Ubuntu recommended)\n- `g++`\n- `libssl-dev`\n- `alsa-utils`\n\n```bash\nsudo apt update\nsudo apt install -y build-essential libssl-dev alsa-utils\n```\n\n### Build\n\n```bash\nmake\n```\n\n### Start Server\n\n```bash\n./server \u003cport\u003e\n```\n\n### Start Clients\n\n```bash\n./client \u003cIP_address\u003e \u003cport\u003e\n```\n\n\u003e 先開 server，再開多個 client 進行互測。\n\n---\n\n## Quick Demo Script\n\nClient 1:\n\n```bash\nregister alice 1234\nlogin alice 1234\n```\n\nClient 2:\n\n```bash\nregister bob 1234\nlogin bob 1234\n```\n\nClient 1 傳私訊給 Client 2:\n\n```text\nsend\n# choose: 2\nsend bob hello\n```\n\nClient 1 傳檔給 Client 2:\n\n```text\nsend\n# choose: 4\nsend bob test.txt\n```\n\n---\n\n## Project Structure\n\n```text\nRT-chat-room/\n├── server.cpp\n├── server.hpp\n├── client.cpp\n├── ThreadPool.cpp\n├── ThreadPool.hpp\n├── UserManager.cpp\n├── UserManager.hpp\n├── myfile.cpp\n├── myfile.hpp\n├── defAndFuc.cpp\n├── defAndFuc.hpp\n├── users.txt               # 帳號資料（明文）\n├── server.crt              # TLS certificate\n├── server.key              # TLS private key\n└── serverFile/             # server 接收檔案目錄（執行時可能自動建立）\n```\n\nRuntime 可能額外產生：\n\n- `clientFile_\u003cusername\u003e/`（client 端接收檔案）\n\n---\n\n## Design Notes and Trade-offs\n\n- **Relay over peer-to-peer**: 實作更單純，集中控管安全與權限。代價是 server 負載較高\n- **Thread pool over one-thread-per-client**: 降低 thread 建立成本。代價是 queue latency 需平衡\n- **Simple local persistence** (`users.txt`): 開發速度快。代價是安全性不足（目前為明文）\n\n---\n\n## Current Limitations\n\n- 允許檔案格式：`txt`、`md`、`wav`\n- 帳號密碼為明文儲存（`users.txt`）\n- CLI 依賴 ANSI color 與 `system(\"clear\")`\n\n---\n\n## Future Improvements\n\n- 導入密碼雜湊（bcrypt/Argon2）取代明文儲存\n- 支援群組聊天室與聊天室歷史訊息\n- 改善傳輸協議（長度前綴封包，取代字串關鍵字判斷）\n- 加入 retry/backoff 與斷線恢復機制\n- 增加自動化測試（單元測試 + 整合測試）\n\n---\n\n## Cleanup\n\n```bash\nmake clean\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsungj921028%2Frt-chat-room","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsungj921028%2Frt-chat-room","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsungj921028%2Frt-chat-room/lists"}