{"id":13578931,"url":"https://github.com/rxi/dyad","last_synced_at":"2025-12-17T05:35:43.914Z","repository":{"id":19342374,"uuid":"22581432","full_name":"rxi/dyad","owner":"rxi","description":"Asynchronous networking for C ","archived":true,"fork":false,"pushed_at":"2020-10-06T10:51:15.000Z","size":104,"stargazers_count":1448,"open_issues_count":16,"forks_count":222,"subscribers_count":70,"default_branch":"master","last_synced_at":"2025-04-02T19:13:30.635Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/rxi.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}},"created_at":"2014-08-03T19:00:04.000Z","updated_at":"2025-03-25T09:31:06.000Z","dependencies_parsed_at":"2022-08-07T09:15:13.987Z","dependency_job_id":null,"html_url":"https://github.com/rxi/dyad","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rxi%2Fdyad","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rxi%2Fdyad/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rxi%2Fdyad/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rxi%2Fdyad/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rxi","download_url":"https://codeload.github.com/rxi/dyad/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247393191,"owners_count":20931805,"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":[],"created_at":"2024-08-01T15:01:35.112Z","updated_at":"2025-12-17T05:35:43.837Z","avatar_url":"https://github.com/rxi.png","language":"C","readme":"\n![dyad.c](https://cloud.githubusercontent.com/assets/3920290/3942261/5de470e4-255d-11e4-95a9-5f97fa9f3a57.png)\n\n## Overview\nDyad.c is an asynchronous networking library which aims to be lightweight,\nportable and easy to use. It can be used both to create small standalone\nservers and to provide network support to existing projects.\n\n## Getting started\nThe [dyad.c](src/dyad.c?raw=1) and [dyad.h](src/dyad.h?raw=1) files can be\ndropped into an existing project; if you're using Windows you will also have to\nlink to `ws2_32`.\n\nAn overview of the API can be found at [doc/api.md](doc/api.md).\n\nUsage examples can be found at [example/](example/).\n\n## Server example\nA simple server which listens on port 8000 and echoes whatever is sent to it:\n```c\n#include \u003cstdlib.h\u003e\n#include \"dyad.h\"\n\nstatic void onData(dyad_Event *e) {\n  dyad_write(e-\u003estream, e-\u003edata, e-\u003esize);\n}\n\nstatic void onAccept(dyad_Event *e) {\n  dyad_addListener(e-\u003eremote, DYAD_EVENT_DATA, onData, NULL);\n  dyad_writef(e-\u003eremote, \"Echo server\\r\\n\");\n}\n\nint main(void) {\n  dyad_init();\n\n  dyad_Stream *serv = dyad_newStream();\n  dyad_addListener(serv, DYAD_EVENT_ACCEPT, onAccept, NULL);\n  dyad_listen(serv, 8000);\n\n  while (dyad_getStreamCount() \u003e 0) {\n    dyad_update();\n  }\n\n  dyad_shutdown();\n  return 0;\n}\n```\n\n## Client example\nA simple example program which connects to a\n[daytime](http://en.wikipedia.org/wiki/Daytime_Protocol) server and prints the\nresponse:\n```c\n#include \u003cstdio.h\u003e\n#include \"dyad.h\"\n\nstatic void onConnect(dyad_Event *e) {\n  printf(\"connected: %s\\n\", e-\u003emsg);\n}\n\nstatic void onData(dyad_Event *e) {\n  printf(\"%s\", e-\u003edata);\n}\n\nint main(void) {\n  dyad_init();\n\n  dyad_Stream *s = dyad_newStream();\n  dyad_addListener(s, DYAD_EVENT_CONNECT, onConnect, NULL);\n  dyad_addListener(s, DYAD_EVENT_DATA,    onData,    NULL);\n  dyad_connect(s, \"time-nw.nist.gov\", 13);\n\n  while (dyad_getStreamCount() \u003e 0) {\n    dyad_update();\n  }\n  \n  dyad_shutdown();\n  return 0;\n}\n```\n\n\n## License\nThis library is free software; you can redistribute it and/or modify it under\nthe terms of the MIT license. See [LICENSE](LICENSE) for details.\n","funding_links":[],"categories":["Networking","Networking and Internet","C","网络和互联网","内存分配","网络","Networking and Internet ##"],"sub_categories":["Advanced books","高级书籍","网络","Physical ###"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frxi%2Fdyad","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frxi%2Fdyad","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frxi%2Fdyad/lists"}