{"id":17007535,"url":"https://github.com/wkhallen/cdtp","last_synced_at":"2026-03-01T02:33:14.929Z","repository":{"id":106424402,"uuid":"238299741","full_name":"WKHAllen/cdtp","owner":"WKHAllen","description":"Modern cross-platform networking interfaces for C.","archived":false,"fork":false,"pushed_at":"2025-03-16T17:56:05.000Z","size":175,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-08T07:43:12.799Z","etag":null,"topics":["c","networking","socket","socket-client","socket-server"],"latest_commit_sha":null,"homepage":"https://wkhallen.com/dtp","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/WKHAllen.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":"2020-02-04T20:29:40.000Z","updated_at":"2025-03-16T17:56:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"dd46d47a-5637-4753-a4e9-79ffdd6df044","html_url":"https://github.com/WKHAllen/cdtp","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/WKHAllen/cdtp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WKHAllen%2Fcdtp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WKHAllen%2Fcdtp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WKHAllen%2Fcdtp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WKHAllen%2Fcdtp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WKHAllen","download_url":"https://codeload.github.com/WKHAllen/cdtp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WKHAllen%2Fcdtp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29959115,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-01T01:47:18.291Z","status":"online","status_checked_at":"2026-03-01T02:00:07.437Z","response_time":124,"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":["c","networking","socket","socket-client","socket-server"],"created_at":"2024-10-14T05:26:03.290Z","updated_at":"2026-03-01T02:33:14.893Z","avatar_url":"https://github.com/WKHAllen.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Data Transfer Protocol for C\n\nModern cross-platform networking interfaces for C.\n\n## Data Transfer Protocol\n\nThe Data Transfer Protocol (DTP) is a larger project to make ergonomic network programming available in any language.\nSee the full project [here](https://wkhallen.com/dtp/).\n\n## Creating a server\n\nA server can be built using the `CDTPServer` implementation:\n\n```c\n#include \"cdtp.h\"\n#include \u003cstdio.h\u003e\n#include \u003cstring.h\u003e\n#include \u003cassert.h\u003e\n\n// Create a server that receives strings and returns the length of each string\nvoid server_on_recv(CDTPServer *server, size_t client_id, void *data, size_t data_size, void *arg)\n{\n    // Send back the length of the string\n    char *str_data = (char *) data;\n    size_t str_len = strlen(str_data) + 1;\n    assert(str_len == data_size);\n    cdtp_server_send(server, client_id, \u0026str_len, sizeof(size_t));\n    // `free` always needs to be called on received data\n    free(data);\n}\n\nvoid server_on_connect(CDTPServer *server, size_t client_id, void *arg)\n{\n    printf(\"Client with ID %zu connected\\n\", client_id);\n}\n\nvoid server_on_disconnect(CDTPServer *server, size_t client_id, void *arg)\n{\n    printf(\"Client with ID %zu disconnected\\n\", client_id);\n}\n\nint main(void)\n{\n    // Start the server\n    CDTPServer *server = cdtp_server(server_on_recv, server_on_connect, server_on_disconnect, NULL, NULL, NULL);\n    cdtp_server_start(server, \"127.0.0.1\", 29275);\n\n    // Stop the server\n    cdtp_sleep(1.0);\n    cdtp_server_stop(server);\n    cdtp_server_free(server);\n\n    return 0;\n}\n```\n\n## Creating a client\n\nA client can be built using the `CDTPClient` implementation:\n\n```c\n#include \"cdtp.h\"\n#include \u003cstdio.h\u003e\n#include \u003cstring.h\u003e\n#include \u003cassert.h\u003e\n\n// Create a client that sends a message to the server and receives the length of the message\nvoid client_on_recv(CDTPClient *client, void *data, size_t data_size, void *arg)\n{\n    // Validate the response\n    size_t *str_len = (size_t *) data;\n    char *message = (char *) arg;\n    printf(\"Received response from server: %zu\\n\", *str_len);\n    assert(*str_len == strlen(message) + 1);\n    // `free` always needs to be called on received data\n    free(data);\n}\n\nvoid client_on_disconnected(CDTPClient *client, void *arg)\n{\n    printf(\"Unexpectedly disconnected from server\\n\");\n}\n\nint main(void) {\n    // Connect to the server\n    char *message = \"Hello, server!\";\n    CDTPClient *client = cdtp_client(client_on_recv, client_on_disconnected, message, NULL);\n    cdtp_client_connect(client, \"127.0.0.1\", 29275);\n\n    // Send a message to the server\n    cdtp_client_send(client, message, strlen(message) + 1);\n\n    // Disconnect from the server\n    cdtp_sleep(1.0);\n    cdtp_client_disconnect(client);\n    cdtp_client_free(client);\n\n    return 0;\n}\n```\n\n## Memory management\n\nAll data received is allocated on the heap. To prevent memory leaks, those who use the library must call `free(...)` on\nthese pieces of data at some point. The same goes for strings returned from the following functions:\n\n- `cdtp_server_get_host(...)`\n- `cdtp_server_get_client_host(...)`\n- `cdtp_client_get_host(...)`\n- `cdtp_client_get_server_host(...)`\n\n## Serialization\n\nUnlike [the C++ implementation](https://github.com/WKHAllen/cppdtp), the protocol cannot serialize types for you. All\nsend and receive operations deal with void pointers (`void *`) and their sizes (`size_t`).\n\n## Compilation\n\nThe protocol has a few dependencies that must be included when compiling:\n\n### Compiling on Windows\n\n- Link Winsock (`-lWs2_32`)\n- Link OpenSSL 3.0\n\n### Compiling on other platforms\n\n- Link pthread (`-lpthread`)\n- Link OpenSSL 3.0\n\nFor more information on the compilation process, see the [Makefile](Makefile).\n\n## Security\n\nInformation security comes included. Every message sent over a network interface is encrypted with AES-256. Key\nexchanges are performed using a 2048-bit RSA key-pair.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwkhallen%2Fcdtp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwkhallen%2Fcdtp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwkhallen%2Fcdtp/lists"}