{"id":21602767,"url":"https://github.com/codeintelligencetesting/tcpserver","last_synced_at":"2025-04-11T02:35:10.267Z","repository":{"id":65431816,"uuid":"449775998","full_name":"CodeIntelligenceTesting/TcpServer","owner":"CodeIntelligenceTesting","description":null,"archived":false,"fork":false,"pushed_at":"2023-06-19T13:07:39.000Z","size":16,"stargazers_count":2,"open_issues_count":2,"forks_count":7,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-03-25T00:04:35.843Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","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/CodeIntelligenceTesting.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":"2022-01-19T16:46:53.000Z","updated_at":"2024-06-21T08:55:37.000Z","dependencies_parsed_at":"2024-11-24T19:14:22.890Z","dependency_job_id":"238e3817-0bc1-4b8c-9a76-76d72fd67ced","html_url":"https://github.com/CodeIntelligenceTesting/TcpServer","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/CodeIntelligenceTesting%2FTcpServer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeIntelligenceTesting%2FTcpServer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeIntelligenceTesting%2FTcpServer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeIntelligenceTesting%2FTcpServer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CodeIntelligenceTesting","download_url":"https://codeload.github.com/CodeIntelligenceTesting/TcpServer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248330051,"owners_count":21085647,"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":[],"created_at":"2024-11-24T19:14:16.768Z","updated_at":"2025-04-11T02:35:10.248Z","avatar_url":"https://github.com/CodeIntelligenceTesting.png","language":"C++","readme":"![cmake workflow](https://github.com/elhayra/tcp_server_client/actions/workflows/cmake.yml/badge.svg)\n\n# TCP server client\nA thin and simple C++ TCP client and server library with an example application.\n\n### Platforms Support\nCurrently, both linux and mac are supported.\n\n### Example Application\nSimple tcp server-client example application. It is optimized for simplicity and ease of use/read but not for performance. However, I believe tuning its code to suite your needs should be easy in most cases.\nYou can find examples of both server and client under the 'examples' directory. Both the library and the examples are well documented.\n\n### Server\nThe server is thread-safe, and can handle multiple clients at the same time, and remove dead clients resources automatically. \n\n## Quick start\nbuild the examples and static library file:\n```bash\n$ cd tcp_server_client\n$ ./build\n```\n\nrun the server and client examples:\nNavigate into the `build` folder and run in the terminal:\n```bash\n$ cd build\n```\nIn terminal #1:\n```bash\n$ ./tcp_server\n```\nIn terminal #2:\n```bash\n$ ./tcp_client\n```\n\n## Building \n\nThis project is set to use CMake to build both the *client example* and the *server example*. In addition, CMake builds a static *library file* to hold the common code to both server and client.\n\nIn order to build the project you can either use the `build.sh` script:\n```bash\n$ cd tcp_server_client\n$ ./build\n```\n\nor build it manually:\n```bash\n$ cd tcp_server_client\n$ mkdir build\n$ cmake ..\n$ make\n```\n\nThe build process generate three files: `libtcp_client_server.a`, `tcp_client` and `tcp_server`.\nThe last two are the executables of the examples which can be executed in the terminal. \n\n\n#### Building Only Server or Client\n\nBy default, the CMake configuration builds both server and client. However, you can use flags to build only one of the apps as follows:\n\n###### Disabling the server build\n\nTo build only the client, disable the server build by replace the `cmake ..` call by:\n\n```bash\ncmake -DSERVER_EXAMPLE=OFF ..\n```\nAnd then run the make command as usual.\n\n###### Disabling the client build\n\nTo build only the server, disable the client build by replace the `cmake ..` call by:\n\n```bash\ncmake -DCLIENT_EXAMPLE=OFF ..\n```\nAnd then run the make command as usual.\n\n## Run the Examples \nNavigate into the `build` folder and run in the terminal:\n```bash\n$ ./tcp_server\n```\n\nYou should see a menu output on the screen, we'll get back to that.\nIn a different terminal, run the client:\n````bash\n$ ./tcp_client\n````\n\nYou should see a similar menu for the client too. In addition, as mentioned, the client will try to connect to the server right away, so you should also see an output messages on both client and server terminals indicating that the connection succeeded.\nNow, feel free to play with each of the client/server menus. You can exchange messages b/w client and server, print active clients etc. You can also spawn more clients in other terminals to see how the server handles multiple clients.\n\n## Server-Client API\n\nAfter playing with the examples, go into the examples source code and have a look at the `main()` function to learn how the server and client interacts. The examples are heavily documented.\nIn addition, you can also look at the public functions in `tcp_client.h` and `tcp_server.h` to learn what APIs are available.\n\n### Server and Client Events \nBoth server and client are using the observer design pattern to register and handle events.\nWhen registering to an event with a callback, you should make sure that:\n- The callback is fast (not doing any heavy lifting tasks) because those callbacks are called from the context of the server or client. \n- No server / client function calls are made in those callbacks to avoid possible deadlock.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeintelligencetesting%2Ftcpserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodeintelligencetesting%2Ftcpserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeintelligencetesting%2Ftcpserver/lists"}