{"id":17007479,"url":"https://github.com/wkhallen/godtp","last_synced_at":"2025-09-02T20:42:34.103Z","repository":{"id":56857870,"uuid":"246882919","full_name":"WKHAllen/godtp","owner":"WKHAllen","description":"Cross-platform networking interfaces for Go.","archived":false,"fork":false,"pushed_at":"2024-03-31T23:51:04.000Z","size":45,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-27T11:22:36.532Z","etag":null,"topics":["golang","networking","socket","socket-client","socket-server"],"latest_commit_sha":null,"homepage":"https://wkhallen.com/dtp","language":"Go","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-03-12T16:35:48.000Z","updated_at":"2022-08-23T19:41:03.000Z","dependencies_parsed_at":"2024-04-01T00:29:44.452Z","dependency_job_id":"3ef203d9-80e2-4100-b194-7452416edf3b","html_url":"https://github.com/WKHAllen/godtp","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WKHAllen%2Fgodtp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WKHAllen%2Fgodtp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WKHAllen%2Fgodtp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WKHAllen%2Fgodtp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WKHAllen","download_url":"https://codeload.github.com/WKHAllen/godtp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244952785,"owners_count":20537472,"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":["golang","networking","socket","socket-client","socket-server"],"created_at":"2024-10-14T05:25:54.064Z","updated_at":"2025-03-22T11:46:58.155Z","avatar_url":"https://github.com/WKHAllen.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Data Transfer Protocol for Go\r\n\r\nCross-platform networking interfaces for Go.\r\n\r\n## Data Transfer Protocol\r\n\r\nThe Data Transfer Protocol (DTP) is a larger project to make ergonomic network programming available in any language.\r\nSee the full project [here](https://wkhallen.com/dtp/).\r\n\r\n## Installation\r\n\r\nInstall the package:\r\n\r\n```sh\r\n$ go get -u github.com/wkhallen/godtp\r\n```\r\n\r\n## Creating a server\r\n\r\nA server can be built using the `Server` implementation:\r\n\r\n```go\r\npackage example\r\n\r\nimport (\r\n\t\"fmt\"\r\n\t\"github.com/wkhallen/godtp\"\r\n)\r\n\r\nfunc main() {\r\n\t// Create a server that receives strings and returns the length of each string\r\n\tserver, serverEvent := godtp.NewServer[int, string]()\r\n\terr := server.Start(\"127.0.0.1\", 29275)\r\n\tif err != nil {\r\n\t\t// Handle server start error\r\n\t}\r\n\r\n\t// Iterate over events\r\n\tfor event := range serverEvent {\r\n\t\tswitch event.EventType {\r\n\t\tcase godtp.ServerConnect:\r\n\t\t\tfmt.Printf(\"Client with ID %d connected\\n\", event.ClientID)\r\n\t\tcase godtp.ServerDisconnect:\r\n\t\t\tfmt.Printf(\"Client with ID %d disconnected\\n\", event.ClientID)\r\n\t\tcase godtp.ServerReceive:\r\n\t\t\t// Send back the length of the string\r\n\t\t\terr := server.Send(len(event.Data), event.ClientID)\r\n\t\t\tif err != nil {\r\n\t\t\t\t// Handle send error\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n## Creating a client\r\n\r\nA client can be built using the `Client` implementation:\r\n\r\n```go\r\npackage example\r\n\r\nimport (\r\n\t\"fmt\"\r\n\t\"github.com/wkhallen/godtp\"\r\n)\r\n\r\nfunc main() {\r\n\t// Create a client that send a message to the server and receives the length of the message\r\n\tclient, clientEvent := godtp.NewClient[string, int]()\r\n\terr := client.Connect(\"127.0.0.1\", 29275)\r\n\tif err != nil {\r\n\t\t// Handle client connect error\r\n\t}\r\n\r\n\t// Send a message to the server\r\n\tmessage := \"Hello, server!\"\r\n\terr = client.Send(message)\r\n\tif err != nil {\r\n\t\t// Handle send error\r\n\t}\r\n\r\n\t// Receive the response\r\n\tevent := \u003c-clientEvent\r\n\tswitch event.EventType {\r\n\tcase godtp.ClientReceive:\r\n\t\t// Validate the response\r\n\t\tfmt.Printf(\"Received response from server: %d\", event.Data)\r\n\t\tif event.Data != len(message) {\r\n\t\t\tfmt.Printf(\"Invalid response: expected %d, received %d\", len(message), event.Data)\r\n\t\t}\r\n\tdefault:\r\n\t\t// Unexpected response\r\n\t\tfmt.Printf(\"Expected to receive a response from the server, instead got %#v\\n\", event)\r\n\t}\r\n}\r\n```\r\n\r\n## Security\r\n\r\nInformation security comes included. Every message sent over a network interface is encrypted with AES-256. Key\r\nexchanges are performed using a 2048-bit RSA key-pair.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwkhallen%2Fgodtp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwkhallen%2Fgodtp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwkhallen%2Fgodtp/lists"}