{"id":20662028,"url":"https://github.com/kilemonn/cpp-socketlibrary","last_synced_at":"2025-07-14T08:32:46.215Z","repository":{"id":165152568,"uuid":"121734119","full_name":"Kilemonn/Cpp-SocketLibrary","owner":"Kilemonn","description":"C++ Network socket library for both Windows and Linux.","archived":false,"fork":false,"pushed_at":"2024-12-26T06:19:41.000Z","size":1421,"stargazers_count":7,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-22T07:44:13.206Z","etag":null,"topics":["cmake","cpp17","library","linux","make","server-socket","socket","socket-library","unit-testing","wifi","windows"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kilemonn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2018-02-16T09:34:42.000Z","updated_at":"2025-04-01T05:09:40.000Z","dependencies_parsed_at":"2024-04-05T09:38:45.459Z","dependency_job_id":"ede81d93-7bf1-4340-a542-a44797c21ddf","html_url":"https://github.com/Kilemonn/Cpp-SocketLibrary","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/Kilemonn/Cpp-SocketLibrary","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kilemonn%2FCpp-SocketLibrary","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kilemonn%2FCpp-SocketLibrary/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kilemonn%2FCpp-SocketLibrary/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kilemonn%2FCpp-SocketLibrary/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kilemonn","download_url":"https://codeload.github.com/Kilemonn/Cpp-SocketLibrary/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kilemonn%2FCpp-SocketLibrary/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265262646,"owners_count":23736441,"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":["cmake","cpp17","library","linux","make","server-socket","socket","socket-library","unit-testing","wifi","windows"],"created_at":"2024-11-16T19:12:38.394Z","updated_at":"2025-07-14T08:32:45.372Z","avatar_url":"https://github.com/Kilemonn.png","language":"C++","readme":"# Cpp-SocketLibrary\n\nA ServerSocket and Socket library for Windows and Linux that supports Wifi communication.\n\n## Getting Started\n\n### Dependencies\n\n- [CMake](https://cmake.org/download/) and `make`\n\n### Building the Library and Running the Tests - Linux\n\n- Make sure `libglib2.0-dev` is installed\n\n1. To build the library, firstly run cmake: `cmake . -B build-linux` in the root directory of the repository (`CppSocketLibrary/`).\n2. Then move into the new `build-linux` folder: `cd build-linux`.\n3. Then you can run `make` to build the library.\n4. Then you can run `make check` to run the available tests.\n\n### Building the Library and Running the Tests - Windows\n\n1. To build the library, firstly run cmake: `cmake . -B build` in the root directory of the repository (`CppSocketLibrary/`).\n2. This will create a `.sln` file which can be opened in `Visual Studio`.\n3. Once opened (and with the appropriate windows service packs installed - `MSVC v143 - VS 2022 C++ x64/x86 Spectre-mitigated libs (v14.29-16.11)`)\n4. You can then build and run the `CppSocketLibraryTest` project and it will rebuild the library and run the appropriate tests.\n\n## Usage Examples\n\n- TCP Example using IPV6:\n\n```cpp\nvoid tcpExample()\n{\n    // Create a new Wifi ServerSocket\n    kt::ServerSocket server(std::nullopt, 56756, 20, kt::InternetProtocolVersion::IPV6);\n\n    // Create new TCP socket\n    kt::TCPSocket client(\"::1\", server.getPort());\n\n    // Accept the incoming connection at the server\n    kt::TCPSocket serverSocket = server.acceptTCPConnection();\n\n    // Send string with text before and after the delimiter\n    const std::string testString = \"TCP Delimiter Test\";\n    const char delimiter = '~';\n    if (!client.send(testString + delimiter + \"other string\").first)\n    {\n        std::cout \u003c\u003c \"Failed to send test string\" \u003c\u003c std::endl;\n        return;\n    }\n\n    if (serverSocket.ready())\n    {\n        std::string response = serverSocket.receiveToDelimiter(delimiter);\n        // Check that the received string is the same as the string sent by the client\n        ASSERT_EQ(response, testString);\n    }\n\n    // Close all sockets\n    client.close();\n    serverSocket.close();\n    server.close();\n}\n```\n\n- UDP Example using IPV4 (the default protocol version - so protocol related arguments are omitted):\n\n```cpp\nvoid udpExample() \n{\n    // The socket receiving data must first be bound\n    kt::UDPSocket socket;\n    socket.bind(std::nullopt, 37893, kt::InternetProtocolVersion::IPV4);\n\n    kt::UDPSocket client;\n    const std::string testString = \"UDP test string\";\n    if (!client.sendTo(\"localhost\", 37893, testString).first.first)\n    {\n        std::cout \u003c\u003c \"Failed to send to address.\" \u003c\u003c std::endl;\n        return;\n    }\n\n    if (socket.ready())\n    {\n        std::pair\u003cstd::optional\u003cstd::string\u003e, std::pair\u003cint, kt::SocketAddress\u003e\u003e recieved = socket.receiveFrom(testString.size());\n        ASSERT_EQ(testString, recieved.first.value());\n    }\n\n    socket.close();\n}\n```\n\n## SIGPIPE Errors\n\n`SIGPIPE` is a signal error raised by UNIX when you attempt to write data to a closed linux socket (closed by the remote). There are a few ways to work around this signal. **Note:** that in both cases, the `kt::TCPSocket.send()` function will return `false` in the result pair so you can detect that the send has failed. *(You can refer to the TCPSocketTest.cpp file and the \"...Linux...\" related tests to do with \"SIGPIPE\" to find examples of the below).*\n\n1. Ignore SIGPIPE signals completely:\n```cpp\n#include \u003ccsignal\u003e\n\nint main()\n{\n    std::signal(SIGPIPE, SIG_IGN);\n\n    ...\n}\n\n```\n\n2. Provide `MSG_NOSIGNAL` as the `flag` argument to the `kt::TCPSocket.send()` function which will ensure no signals are raised during the `kt::TCPSocket.send()` call.\n```cpp\n#include \u003ccsignal\u003e\n\n...\nkt::TCPSocket socket; // Initialise properly\n...\nif (!socket.send(std::string(message), MSG_NOSIGNAL).first)\n{\n    // Remote has closed connection, you can choose to close the current socket or any other work that is required when the connection is broken\n}\n...\n```\n\n3. Setup a handler function to be called with the `SIGPIPE` signal is raised.\n```cpp\n#include \u003ccsignal\u003e\n\nvoid handleSignal(int signal)\n{\n    if (signal == SIGPIPE)\n    {\n        ...\n    }\n}\n\nint main()\n{\n    // Set your handler function to be called when the signal is raised\n    std::signal(SIGPIPE, handleSignal);\n    ...\n\n    // If you want to restore the default signal handling behaviour you can do the following\n    std::signal(SIGPIPE, SIG_DFL);\n}\n```\n\n## NOTE: UDP Read Sizes\n\n- Take care when reading UDP messages. If you do not read the entire length of the message the rest of the data will be lost.\n\n## Running the tests Dockerfile\n\nThe dockerfile is aimed at testing the socket behaviour across a few different flavours of linux to check it is functioning correctly. Especially since development is being done on WSL and there could be some slight differences.\n\n`docker build -f Environment-Test-Dockerfile .`\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkilemonn%2Fcpp-socketlibrary","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkilemonn%2Fcpp-socketlibrary","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkilemonn%2Fcpp-socketlibrary/lists"}