{"id":19614921,"url":"https://github.com/leancloud/cpp-socket-demo","last_synced_at":"2025-02-26T17:43:52.609Z","repository":{"id":66228549,"uuid":"540349013","full_name":"leancloud/cpp-socket-demo","owner":"leancloud","description":"A demo for LeanEngine C++ Runtime and socket features","archived":false,"fork":false,"pushed_at":"2023-04-14T06:26:42.000Z","size":20,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-09T10:33:27.426Z","etag":null,"topics":["leanengine"],"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/leancloud.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":"2022-09-23T08:33:22.000Z","updated_at":"2024-07-24T08:44:39.000Z","dependencies_parsed_at":"2023-05-01T09:00:34.853Z","dependency_job_id":null,"html_url":"https://github.com/leancloud/cpp-socket-demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancloud%2Fcpp-socket-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancloud%2Fcpp-socket-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancloud%2Fcpp-socket-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancloud%2Fcpp-socket-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leancloud","download_url":"https://codeload.github.com/leancloud/cpp-socket-demo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240906868,"owners_count":19876684,"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":["leanengine"],"created_at":"2024-11-11T10:54:30.384Z","updated_at":"2025-02-26T17:43:52.604Z","avatar_url":"https://github.com/leancloud.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# C++ Socket Demo\n\n- (`tcp-game.cpp`) A multithreading TCP game server listening on port 4000.\n- (`udp-echo.cpp`) A UDP echo server listening on port 4000.\n- (`http.cpp`) A multithreading HTTP Server on port 3000, with 0 - 999ms random delay.\n- Graceful shutdown for TCP and HTTP.\n\nOther versions:\n\n- Makefile (current)\n- [CMake](https://github.com/leancloud/cpp-socket-demo/tree/cmake)\n- [Bazel](https://github.com/leancloud/cpp-socket-demo/tree/bazel)\n\n## Build and start server\n\n```\n$ make \u0026\u0026 ./cpp-socket\n[UDP] Socket is listening on 4000\n[TCP] Socket is listening on 4000\n[HTTP] Socket is listening on 3000\n```\n\n## TCP Game\n\nEstablish two connections to server.\n\nconnection #1:\n\n```\n$ nc 127.0.0.1 4000\n\u003e\u003e 1 players online, last number is 1, you must send the next number but skip numbers which multiples of 3 or includes the digit 3.\n2   (your input)\n\u003e\u003e 2 players online, 127.0.0.1:59385 sent 2.\n\u003e\u003e 127.0.0.1:59897 lost, 2 players online.\n4   (your input)\n\u003e\u003e 1 players online, 127.0.0.1:59385 sent 4.\n```\n\nconnection #2:\n\n```\n$ nc 127.0.0.1 4000\n\u003e\u003e 2 players online, last number is 1, you must send the next number but skip numbers which multiples of 3 or includes the digit 3.\n\u003e\u003e 2 players online, 127.0.0.1:59385 sent 2.\n3   (your input)\n\u003e\u003e you are lost\n(disconnected)\n```\n\n## UDP Echo\n\n```\n$ nc -u 127.0.0.1 4000\nhello                   (your input)\nhello                   (response)\n```\n\n## HTTP\n\n```\n$ curl http://127.0.0.1:3000\nHello\n```\n\n## Graceful shutdown\n\nYou can send `SIGTERM` or `SIGINT` (`ctrl-C`) to start graceful shutdown:\n\n```\n$ ./cpp-socket\n[UDP] Socket is listening on 4000\n[TCP] Socket is listening on 4000\n[HTTP] Socket is listening on 3000\n[TCP] A connection is accepted now.\n[TCP] 127.0.0.1 connected...\n(ctrl-C)\n[SIGNAL] 2 workers are running, waiting for them finish ...\n(wait for all connections disconnect)\n[TCP] 127.0.0.1 disconnected.\n(exited)\n```\n\n## Documentation\n\n- [云引擎服务总览](https://docs.leancloud.cn/sdk/engine/overview)\n- 云引擎 C++ 运行环境（WIP）\n- 云引擎游戏后端开发指南（WIP）\n- [命令行工具 CLI 使用指南](https://docs.leancloud.cn/sdk/engine/cli/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleancloud%2Fcpp-socket-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleancloud%2Fcpp-socket-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleancloud%2Fcpp-socket-demo/lists"}