{"id":45687685,"url":"https://github.com/eclipse-ecal/tcp_pubsub","last_synced_at":"2026-02-24T15:09:43.129Z","repository":{"id":43132122,"uuid":"444457932","full_name":"eclipse-ecal/tcp_pubsub","owner":"eclipse-ecal","description":"📦 TCP based publish-subscribe library for C++ 🌐","archived":false,"fork":false,"pushed_at":"2025-04-09T10:47:54.000Z","size":181,"stargazers_count":42,"open_issues_count":4,"forks_count":20,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-09T11:19:47.730Z","etag":null,"topics":["cpp","publish-subscribe","tcp"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eclipse-ecal.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-04T14:52:59.000Z","updated_at":"2025-04-09T10:47:58.000Z","dependencies_parsed_at":"2025-02-26T13:24:47.251Z","dependency_job_id":"238ff85d-c6ba-4be3-b9c5-8d44e650bf5a","html_url":"https://github.com/eclipse-ecal/tcp_pubsub","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/eclipse-ecal/tcp_pubsub","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eclipse-ecal%2Ftcp_pubsub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eclipse-ecal%2Ftcp_pubsub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eclipse-ecal%2Ftcp_pubsub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eclipse-ecal%2Ftcp_pubsub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eclipse-ecal","download_url":"https://codeload.github.com/eclipse-ecal/tcp_pubsub/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eclipse-ecal%2Ftcp_pubsub/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29786987,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-24T10:45:18.109Z","status":"ssl_error","status_checked_at":"2026-02-24T10:45:09.911Z","response_time":75,"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":["cpp","publish-subscribe","tcp"],"created_at":"2026-02-24T15:09:38.781Z","updated_at":"2026-02-24T15:09:43.123Z","avatar_url":"https://github.com/eclipse-ecal.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Windows](https://github.com/eclipse-ecal/tcp_pubsub/actions/workflows/build-windows.yml/badge.svg)](https://github.com/eclipse-ecal/tcp_pubsub/actions/workflows/build-windows.yml) [![Ubuntu](https://github.com/eclipse-ecal/tcp_pubsub/actions/workflows/build-ubuntu.yml/badge.svg)](https://github.com/eclipse-ecal/tcp_pubsub/actions/workflows/build-ubuntu.yml) [![macOS](https://github.com/eclipse-ecal/tcp_pubsub/actions/workflows/build-macos.yml/badge.svg)](https://github.com/eclipse-ecal/tcp_pubsub/actions/workflows/build-macos.yml)\n\n# tcp_pubsub - TCP Publish/Subscribe library\n\ntcp_pubsub is a minimal publish-subscribe library that transports data via TCP. The project is CMake based. The dependencies are integrated as git submodules. In your own Project you can either use those submodules as well, or provide the dependencies in your own manner.\n\ntcp_pubsub does not define a message format but only transports binary blobs. It does however define a protocol around that, which is kept as lightweight as possible.\n\nDependencies:\n\n- [asio](https://github.com/chriskohlhoff/asio.git)\n- [recycle](https://github.com/steinwurf/recycle.git)\n\n## Hello World Example\n\nA very similar Example is also provided in the repository.\n\n### Publisher\n\n```cpp\n#include \u003cthread\u003e\n\n#include \u003ctcp_pubsub/executor.h\u003e\n#include \u003ctcp_pubsub/publisher.h\u003e\n\nint main()\n{\n  // Create a \"Hello World\" buffer\n  std::string data_to_send = \"Hello World\";\n  \n  // Create an Executor with a thread-pool size of 6. If you create multiple\n  // publishers and subscribers, they all should share the same Executor.\n  std::shared_ptr\u003ctcp_pubsub::Executor\u003e executor = std::make_shared\u003ctcp_pubsub::Executor\u003e(6);\n  \n  // Create a publisher that will offer the data on port 1588\n  tcp_pubsub::Publisher hello_world_publisher(executor, 1588);\n\n  for (;;)\n  {\n    // Send the \"Hello World\" string by passing the pointer to the first\n    // character and the length.\n    hello_world_publisher.send(\u0026data_to_send[0], data_to_send.size());\n\n    std::this_thread::sleep_for(std::chrono::milliseconds(500));\n  }\n\n  return 0;\n}\n```\n\n### Subscriber\n\n```cpp\n#include \u003ciostream\u003e\n#include \u003cthread\u003e\n\n#include \u003ctcp_pubsub/executor.h\u003e\n#include \u003ctcp_pubsub/subscriber.h\u003e\n\nint main()\n{\n  // Create an Executor with a thread-pool size of 6. If you create multiple\n  // publishers and subscribers, they all should share the same Executor.\n  std::shared_ptr\u003ctcp_pubsub::Executor\u003e executor = std::make_shared\u003ctcp_pubsub::Executor\u003e(6);\n\n  // Create a subscriber\n  tcp_pubsub::Subscriber hello_world_subscriber(executor);\n  \n  // Add a session to the subscriber that connects to port 1588 on localhost. A \n  // subscriber will aggregate traffic from multiple source, if you add multiple\n  // sessions.\n  hello_world_subscriber.addSession(\"127.0.0.1\", 1588);\n\n  // Create a Callback that will be called each time a data packet is received.\n  // This function will create an std::string from the packet and print it to\n  // the console.\n  std::function\u003cvoid(const tcp_pubsub::CallbackData\u0026 callback_data)\u003e callback_function\n        = [](const tcp_pubsub::CallbackData\u0026 callback_data) -\u003e void\n          {\n            std::cout \u003c\u003c \"Received playload: \"\n                      \u003c\u003c std::string(callback_data.buffer_-\u003edata(), callback_data.buffer_-\u003esize())\n                      \u003c\u003c std::endl;\n          };\n\n  // Set the callback to the subsriber\n  hello_world_subscriber.setCallback(callback_function);\n    \n  // Prevent the application from exiting immediatelly\n  for (;;) std::this_thread::sleep_for(std::chrono::milliseconds(500));\n  return 0;\n}\n```\n\n## CMake Options\n\nYou can set the following CMake Options to control how tcp_pubsub is built:\n\n| Option                             | Type  | Default | Explanation                                                                                                                                         |\n|------------------------------------|-------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------|\n| `TCP_PUBSUB_BUILD_SAMPLES`         | `BOOL`| `ON`    | Build project samples.                                                                                                                              |\n| `TCP_PUBSUB_BUILD_ECAL_SAMPLES`    | `BOOL`| `OFF`   | Build eCAL-based project samples. Requires eCAL to be findable by CMake.                                                                            |\n| `TCP_PUBSUB_USE_BUILTIN_ASIO`      | `BOOL`| `ON`    | Use the builtin asio submodule. If set to `OFF`, asio must be available from somewhere else (e.g. system libs).                                     |\n| `TCP_PUBSUB_USE_BUILTIN_RECYCLE`   | `BOOL`| `ON`    | Use the builtin `steinwurf::recycle` submodule. If set to `OFF`, recycle must be available from somewhere else (e.g. system libs).                  |\n| `TCP_PUBSUB_BUILD_TESTS`           | `BOOL`| `OFF`   | Build the tcp_pubsub tests. Requires Gtest::GTest to be findable by CMake. |\n| `TCP_PUBSUB_USE_BUILTIN_GTEST`     | `BOOL`| `ON` (if building tests) | Use the builtin GoogleTest submodule. Only needed if `TCP_PUBSUB_BUILD_TESTS` is `ON`. If set to `OFF`, GoogleTest must be available from elsewhere. |\n| `TCP_PUBSUB_LIBRARY_TYPE`          | `STRING` |             | Controls the library type of tcp_pubsub by injecting the string into the `add_library` call. Can be set to STATIC / SHARED / OBJECT. If set, this will override the regular `BUILD_SHARED_LIBS` CMake option. If not set, CMake will use the default setting, which is controlled by `BUILD_SHARED_LIBS`.                |\n\n## How to checkout and build\n\nThere are several examples provided that aim to show you the functionality.\n\n1. Install cmake and git / git-for-windows\n\n2. Checkout this repo and the asio submodule\n\t```console\n\tgit clone https://github.com/eclipse-ecal/tcp_pubsub.git\n\tcd tcp_pubsub\n\tgit submodule init\n\tgit submodule update\n\t```\n\n3. CMake the project *(Building as debug will add some debug output)*\n\t```console\n\tmkdir _build\n\tcd _build\n\tcmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=_install\n\t```\n\n4. Build the project\n\t- Linux: `make`\n\t- Windows: Open `_build\\tcp_pubsub.sln` with Visual Studio and build one of the example projects\n\n5. Start either of the example pairs on the same machine.\n\t- `hello_world_publisher /.exe` + `hello_world_subscriber /.exe`\n\t  *or*\n\t- `performance_publisher /.exe` + `performance_subscriber /.exe`\n\n## The Protocol (Version 0)\n\nWhen using this library, you do not need to know how the protocol works. Both the subscriber and receiver are completely implemented and ready for you to use. This section is meant for advanced users that are interested in the underlying protocol.\n\n\u003cdetails\u003e\n\u003csummary\u003eShow\u003c/summary\u003e\n\n### Message flow\n\nThe Protocol is quite simple:\n\n1. The **Subsriber** connects to the publisher and sends a ProtocolHandshakeRequest. This Message contains the maximum protocol Version the Subscriber supports\n\n2. The **Publisher** returns a ProtocolHandshakeResponse. This message contains the protocol version that will be used from now on. The version must not be higher than the version sent by the subsriber.\n\n3. The **Publisher** starts sending data to the subsriber.\n\n_The ProtocolHandshake is meant to provide future-proof expansions. At the moment the only available protocol version is 0._\n\n```\nSubscriber                     Publisher\n   |                               |\n   |  -\u003e ProtocolHandshakeReq  -\u003e  |\n   |                               |\n   |  \u003c- ProtocolHandshakeResp \u003c-  |\n   |                               |\n   |  \u003c--------- DATA \u003c----------  |\n   |  \u003c--------- DATA \u003c----------  |\n   |  \u003c--------- DATA \u003c----------  |\n   |              ...              |\n```\n\n### Message layout\n\nThe protocol uses the following message layout. Values that are not sent by the sender are to be interpreted as 0.\n\n- **General Message header**\n\tEach message will have a message header as follows. Values are to be interpreted little-endian.\n\tThis header is defined in [tcp_pubsub/src/tcp_header.h](tcp_pubsub/src/tcp_header.h)\n\n\t- 16 bit: Header size\n\t- 8 bit: Type\n\t\t- 0 = Regular Payload\n\t\t- 1 = Handshake Message\n\t- 8 bit: Reserved\n\t\t- Must be 0\n\t- 64bit: Payload size\n\n2. **ProtocolHandshakeReq \u0026 ProtocolHandshakeResp**\n\tThe layout of ProtocolHandshakeReq / ProtocolHandshakeResp is the same.  Values are to be interpreted little-endian\n\tThis message is defined in [tcp_pubsub/src/protocol_handshake_message.h](tcp_pubsub/src/protocol_handshake_message.h)\n\t\n\t- Message Header (size given in the first 16 bit)\n\t- 8 bit: Protocol Version\n\n\u003c/details\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feclipse-ecal%2Ftcp_pubsub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feclipse-ecal%2Ftcp_pubsub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feclipse-ecal%2Ftcp_pubsub/lists"}