{"id":16382659,"url":"https://github.com/jeremyko/asocklib","last_synced_at":"2025-10-24T17:43:25.174Z","repository":{"id":60898747,"uuid":"80982415","full_name":"jeremyko/ASockLib","owner":"jeremyko","description":"a simple, easy to use cross-platform c++11 header-only socket library for linux, macOS, windows","archived":false,"fork":false,"pushed_at":"2025-05-02T13:58:12.000Z","size":529,"stargazers_count":19,"open_issues_count":0,"forks_count":10,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-10-09T01:08:34.943Z","etag":null,"topics":["cross-platform","domain-socket","epoll","iocp","kqueue","tcp","udp","winsock"],"latest_commit_sha":null,"homepage":"","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/jeremyko.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2017-02-05T09:22:31.000Z","updated_at":"2025-08-30T21:04:44.000Z","dependencies_parsed_at":"2024-10-28T15:24:11.934Z","dependency_job_id":"2be56916-201a-46eb-b403-829fd9520108","html_url":"https://github.com/jeremyko/ASockLib","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/jeremyko/ASockLib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeremyko%2FASockLib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeremyko%2FASockLib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeremyko%2FASockLib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeremyko%2FASockLib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jeremyko","download_url":"https://codeload.github.com/jeremyko/ASockLib/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeremyko%2FASockLib/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000722,"owners_count":26082894,"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","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["cross-platform","domain-socket","epoll","iocp","kqueue","tcp","udp","winsock"],"created_at":"2024-10-11T04:05:59.843Z","updated_at":"2025-10-09T01:12:38.597Z","avatar_url":"https://github.com/jeremyko.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ASockLib\n\n## Features\n\n**A C++11 header-only, simple and easy cross-platform socket library.**\n\n- Supports TCP, UDP and Unix Domain Socket(UDS).\n- It performs buffering internally(TCP,UDS).\n- When all user data is received, the user-specified callback is called.\n- No repeat send calls until all are sent. When send returns\nWSAEWOULDBLOCK / EWOULDBLOCK / EAGAIN, It will be added to the queue and sent later.\n- Composition or Inheritance class usage.\n- Using epoll (linux), kqueue (macOS) and winsock (windows).\n- No additional dependencies required.\n\n## Install and use asock in your project\n\n- ### Option 1: Including the source code directly in your project  \n\n  This is a header-only library, so you can just add the asock folder\n  to your project include directory.\n\n  ```\n  cp -r asock your_include_path/.\n  ```\n  \n- ### Option 2: Using CMake FetchContent  \n\n  Add below code to your CMake file\n\n  ```\n  include(FetchContent)\n  fetchcontent_declare(\n      asock\n      GIT_REPOSITORY https://github.com/jeremyko/ASockLib\n      GIT_TAG        fa7b362998157972b48b2c30042d0c13c8557bfc #1.0.7\n  )\n  fetchcontent_makeavailable(asock)\n  ```\n  \n- ### Option 3: Using [vcpkg](https://github.com/microsoft/vcpkg)\n\n  ```\n  vcpkg install asock\n  ```\n  \n- ### Option 4: Installing locally using CMake\n\n  The test code has a [googletest](https://github.com/google/googletest) dependency.\n  If you are simply installing asock, no test code compilation is required.\n  The sample code has no dependencies, but is not required for asock installation.\n  That's why `DJEREMYKO_ASOCK_BUILD_TESTS=OFF`\n  and `-DJEREMYKO_ASOCK_BUILD_SAMPLES=OFF` are used.\n\n  ```\n  mkdir build\n  cd build\n  cmake .. -DJEREMYKO_ASOCK_BUILD_TESTS=OFF -DJEREMYKO_ASOCK_BUILD_SAMPLES=OFF\n  sudo make install\n  ```\n\n  ### Once installed with the option 2,3,4, you can use asock using cmake like this: \n\n  ```\n  find_package(asock CONFIG REQUIRED)\n  target_link_libraries(yours PRIVATE asock::asock)\n  ```\n\n## Sample code\nThe following is a tcp echo example using class inheritance. See the sample folder for all examples. \nYou can find composition usage and udp, domain socket example too.\n\n### tcp echo server\n\n```cpp\n//This is an inheritance usage.  \n#include \"asock/asock_tcp_server.hpp\"\n\n#define DEFAULT_PACKET_SIZE 1024\nclass Server : public asock::ASockTcpServer {\n  private:\n    bool OnRecvedCompleteData(asock::Context* context_ptr,\n                              const char* const data_ptr, size_t len) override {\n        //user specific : - your whole data has arrived.\n        char packet[DEFAULT_PACKET_SIZE];\n        memcpy(\u0026packet, data_ptr,len );\n        packet[len] = '\\0';\n        std::cout \u003c\u003c \"recved [\" \u003c\u003c packet \u003c\u003c \"]\\n\";\n        if(! tcp_server_.SendData(context_ptr, data_ptr, len) ) {\n            std::cerr \u003c\u003c GetLastErrMsg() \u003c\u003c\"\\n\"; \n            return false;\n        }\n        return true;\n    }\n    void OnClientConnected(asock::Context* context_ptr) override {\n        std::cout \u003c\u003c \"client connected : socket fd [\"\u003c\u003c context_ptr-\u003esocket \u003c\u003c\"]\\n\";\n    }\n    void OnClientDisconnected(asock::Context* context_ptr) override {\n        std::cout \u003c\u003c \"client disconnected : socket fd [\"\u003c\u003c context_ptr-\u003esocket \u003c\u003c\"]\\n\";\n    }\n};\n\nint main(int argc, char* argv[]) {\n    Server Server; \n    if(!Server.RunTcpServer(\"127.0.0.1\", 9990 )) {\n        std::cerr \u003c\u003c Server.GetLastErrMsg() \u003c\u003c\"\\n\"; \n        exit(EXIT_FAILURE);\n    }\n    std::cout \u003c\u003c \"server started\" \u003c\u003c \"\\n\";\n    while( Server.IsServerRunning() ) {\n        std::this_thread::sleep_for(std::chrono::seconds(1));\n    }\n    std::cout \u003c\u003c \"server exit...\\n\";\n    exit(EXIT_SUCCESS);\n}\n\n```\n\n#### tcp echo client\n\n```cpp\n//This is an inheritance usage.  \n#include \"asock/asock_tcp_client.hpp\"\n\n#define DEFAULT_PACKET_SIZE 1024\nclass Client : public asock::ASockTcpClient {\n  private:\n    bool OnRecvedCompleteData(asock::Context* ,\n                              const char* const data_ptr, size_t len) override {\n        //user specific : - your whole data has arrived.\n        char packet[DEFAULT_PACKET_SIZE];\n        memcpy(\u0026packet,data_ptr ,len);\n        packet[len] = '\\0';\n        std::cout \u003c\u003c \"server response [\" \u003c\u003c packet \u003c\u003c \"]\\n\";\n        return true;\n    }\n    void OnDisconnectedFromServer() override {\n        std::cout \u003c\u003c \"server disconnected, terminate client\\n\";\n        client_.Disconnect();\n    }\n};\n\nint main(int argc, char* argv[]) {\n    Client client;\n    if(!client.InitTcpClient(\"127.0.0.1\", 9990 ) ) {\n        std::cerr \u003c\u003c client.GetLastErrMsg() \u003c\u003c\"\\n\"; \n        exit(EXIT_FAILURE);\n    }\n    std::string user_msg  {\"\"}; \n    while( client.IsConnected() ) {\n        std::cin.clear();\n        getline(std::cin, user_msg); \n        int msg_len = user_msg.length();\n        if(msg_len\u003e0) {\n            if(! client.SendToServer(user_msg.c_str(), msg_len) ) {\n                std::cerr \u003c\u003c client.GetLastErrMsg() \u003c\u003c\"\\n\"; \n                exit(EXIT_FAILURE);\n            }\n        }\n    } //while\n    exit(EXIT_SUCCESS);\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeremyko%2Fasocklib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjeremyko%2Fasocklib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeremyko%2Fasocklib/lists"}